:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e8eef5;
  --muted: #8b9cb3;
  --accent: #5b9fd4;
  --accent-hover: #7ab3e0;
  --border: #2d3a4d;
  --danger: #c45c5c;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse 120% 80% at 50% -20%, #1e3a5f 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
}

.page {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.back-to-today {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  padding: 0.4rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.page:has(.back-to-today:not(.hidden)) .header {
  padding-right: 5.25rem;
}

@media (max-width: 480px) {
  .back-to-today {
    top: 0.65rem;
    right: 0.65rem;
    font-size: 0.75rem;
    padding: 0.35rem 0.5rem;
  }
}

.header h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  min-height: 1.5em;
}

.subtitle:empty {
  display: none;
}

.toolbar {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.btn-random {
  font-weight: 600;
}

.difficulty {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-bottom: 1.25rem;
}

.diff-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.diff-btn:hover {
  border-color: var(--muted);
}

.diff-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0f14;
  font-weight: 600;
}

.diff-btn:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}

.main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 1rem;
}

.puzzle-frame {
  margin: 0;
  text-align: center;
}

.puzzle-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.puzzle-stage.hidden {
  display: none;
}

.hint-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hint-mark {
  position: absolute;
  transform: translate(-50%, -50%);
  image-rendering: auto;
}

.puzzle-placeholder {
  margin: 0;
  padding: 2.5rem 1.25rem;
  border-radius: var(--radius);
  background: #0a0e14;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.puzzle-placeholder strong {
  color: var(--text);
  font-weight: 600;
}

.puzzle-placeholder.hidden {
  display: none;
}

.puzzle-img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  border-radius: var(--radius);
  background: #0a0e14;
}

.puzzle-img.hidden {
  display: none;
}

.image-error {
  margin: 1rem 0 0;
  padding: 1rem;
  border-radius: var(--radius);
  background: rgba(196, 92, 92, 0.12);
  border: 1px solid rgba(196, 92, 92, 0.35);
  color: #f0b4b4;
  font-size: 0.9rem;
}

.image-error.hidden {
  display: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  align-items: flex-start;
  margin-top: 1.25rem;
}

.hint-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  max-width: min(28rem, 100%);
}

.hint-usage-note {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
  white-space: pre-line;
}

.hint-usage-note.hidden {
  display: none;
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius);
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--accent);
  color: #0a0f14;
}

.btn-secondary:hover {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--muted);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.btn-ghost:disabled:hover {
  color: var(--muted);
  border-color: var(--border);
}

.btn.hidden {
  display: none;
}

.footer {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.footer-link {
  color: inherit;
  text-decoration: none;
  padding: 0.15rem 0.25rem;
  border-radius: 8px;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.footer-link:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}

.footer-link:hover {
  color: var(--text);
  background: rgba(91, 159, 212, 0.08);
  border-bottom-color: rgba(232, 238, 245, 0.35);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.lang-picker {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}

.lang-select {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem 2rem 0.4rem 0.65rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b9cb3' d='M3 4.5L6 7.5L9 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  min-width: 10.5rem;
  max-width: 100%;
}

.lang-select:hover {
  border-color: var(--muted);
}

.lang-select:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}
