:root {
  color-scheme: light;
  --bg: #e8dfcb;
  --ink: #2b2b26;
  --soft-ink: #6b6456;
  --panel: #bfb6a3;
  --panel-dark: #a7a08e;
  --accent: #7a6a52;
  --line: #9c927f;
  --grid-line: rgba(122, 106, 82, 0.22);
  --grid-bold: rgba(122, 106, 82, 0.48);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Alegreya", "Times New Roman", serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  background-image:
    radial-gradient(circle at 15% 10%, rgba(255, 255, 255, 0.6), transparent 55%),
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.45), transparent 50%),
    linear-gradient(120deg, rgba(120, 109, 88, 0.16), transparent 40%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='800' height='500' viewBox='0 0 800 500'><path fill='%23c6bda7' d='M0 40c140 20 220 80 400 70s260-60 400-80v70c-110 20-230 50-400 45S140 120 0 110z'/><path fill='%23d7cdb8' d='M0 260c200 30 260 90 400 80s250-80 400-120v100c-120 40-240 60-400 60S160 340 0 330z'/></svg>");
  background-size: cover, cover, cover, 1100px;
  background-attachment: fixed;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 20px 20px;
}

.hero {
  display: flex;
  gap: 20px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.hero-text h1 {
  font-family: "Calligraffitti", cursive;
  font-size: clamp(2.2rem, 4.6vw, 3.9rem);
  letter-spacing: 0.03em;
}

.hero-text p {
  color: var(--soft-ink);
  font-size: 0.98rem;
}

.auth-card {
  min-width: 300px;
  max-width: 360px;
  background: rgba(232, 223, 203, 0.76);
  border: 1px solid rgba(122, 106, 82, 0.26);
  border-radius: 16px;
  padding: 12px;
}

.auth-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.auth-row input {
  width: 100%;
  border: 1px solid rgba(122, 106, 82, 0.38);
  border-radius: 10px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.65);
}

.auth-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.small {
  padding: 7px 12px;
  font-size: 0.92rem;
}

.auth-name {
  font-weight: 600;
}

.auth-status {
  margin-top: 8px;
  color: var(--soft-ink);
  min-height: 1.2em;
  font-size: 0.95rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(200px, 240px) 1fr;
  gap: 16px;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-item {
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  border-radius: 18px;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
  font-size: 1.2rem;
  color: var(--ink);
}

.menu-item:hover,
.menu-item:focus-visible {
  transform: translateX(4px);
  background: rgba(122, 106, 82, 0.12);
}

.menu-item.is-active {
  background: rgba(122, 106, 82, 0.18);
  box-shadow: inset 0 0 0 1px rgba(122, 106, 82, 0.4);
}

.menu-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #d1c7b1;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 600;
}

.practice {
  background: rgba(232, 223, 203, 0.7);
  border-radius: 28px;
  padding: 16px;
  box-shadow: 0 24px 40px rgba(47, 40, 29, 0.12);
  border: 1px solid rgba(122, 106, 82, 0.2);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.practice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 12px;
}

.header-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.pickers-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.picker-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.group-picker-label {
  font-size: 0.88rem;
  color: var(--soft-ink);
}

.group-picker {
  border: 1px solid rgba(122, 106, 82, 0.4);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--ink);
  font-family: "Alegreya", serif;
  font-size: 1rem;
  padding: 7px 9px;
  min-width: 170px;
}

.practice-header h2 {
  font-size: 1.6rem;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--soft-ink);
}

.question {
  font-size: clamp(2.8rem, 5vw, 4rem);
  color: var(--accent);
  font-weight: 600;
}

.canvas-wrap {
  position: relative;
  background: var(--panel);
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(122, 106, 82, 0.35);
  width: min(100%, clamp(240px, 36vh, 400px));
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
  cursor: crosshair;
  position: relative;
  z-index: 2;
}

.canvas-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      to right,
      transparent 0,
      transparent calc(12.5% - 1px),
      var(--grid-line) calc(12.5% - 1px),
      var(--grid-line) 12.5%
    ),
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent calc(12.5% - 1px),
      var(--grid-line) calc(12.5% - 1px),
      var(--grid-line) 12.5%
    );
  z-index: 0;
  pointer-events: none;
}

.canvas-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      to right,
      transparent calc(50% - 1px),
      var(--grid-bold) calc(50% - 1px),
      var(--grid-bold) calc(50% + 1px),
      transparent calc(50% + 1px)
    ),
    linear-gradient(
      to bottom,
      transparent calc(50% - 1px),
      var(--grid-bold) calc(50% - 1px),
      var(--grid-bold) calc(50% + 1px),
      transparent calc(50% + 1px)
    );
  z-index: 1;
  pointer-events: none;
}

.hint-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(5.6rem, 14vw, 9.4rem);
  line-height: 0.9;
  color: rgba(43, 43, 38, 0.22);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  font-weight: 700;
  transform: translateY(0);
  transform-origin: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 3;
}

.hint-overlay.is-visible {
  opacity: 1;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0 6px;
}

button {
  font-family: "Alegreya", serif;
}

.ghost,
.solid,
.hint-button,
.pill {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 1rem;
  cursor: pointer;
}

.ghost {
  background: transparent;
  border: 1px solid rgba(122, 106, 82, 0.6);
  color: var(--ink);
}

.solid {
  background: var(--accent);
  color: #f8f5ee;
  box-shadow: 0 12px 24px rgba(66, 57, 44, 0.2);
}

.hint-button {
  background: rgba(122, 106, 82, 0.14);
}

.answer-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 16px;
}

.result {
  font-weight: 600;
  color: var(--soft-ink);
}

.hint-text {
  color: var(--soft-ink);
  font-size: 0.98rem;
  min-width: 260px;
}

.progress-mini {
  color: var(--soft-ink);
  font-size: 0.96rem;
}

.words-panel {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed rgba(122, 106, 82, 0.35);
}

.kanji-meta-row {
  margin: 3px 0;
  color: var(--soft-ink);
  font-size: 0.95rem;
}

.kanji-examples {
  margin-top: 6px;
  padding-left: 18px;
  color: var(--soft-ink);
  display: block;
}

.kanji-examples li {
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.kanji-side-panel {
  position: absolute;
  right: 12px;
  top: 74px;
  width: min(380px, calc(100% - 24px));
  max-height: calc(100% - 86px);
  overflow: auto;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(122, 106, 82, 0.25);
  background: rgba(232, 223, 203, 0.95);
  box-shadow: 0 14px 28px rgba(66, 57, 44, 0.15);
  z-index: 6;
}

.kanji-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.words-toggle {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.pill {
  background: rgba(122, 106, 82, 0.18);
}

.pill.is-active {
  background: var(--accent);
  color: #f8f5ee;
}

.input-row {
  display: flex;
  gap: 12px;
}

#text-input {
  width: min(520px, 100%);
  font-size: 1.1rem;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid rgba(122, 106, 82, 0.4);
  background: rgba(255, 255, 255, 0.7);
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .menu {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .menu-item {
    flex: 1 1 45%;
  }

  .practice-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-side {
    align-items: flex-start;
  }

  .pickers-row {
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
  }

  .kanji-side-panel {
    position: static;
    width: 100%;
    max-height: none;
    margin-top: 10px;
  }

  .answer-row {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-height: 920px) and (min-width: 901px) {
  .app {
    padding: 12px 16px 12px;
  }

  .hero {
    margin-bottom: 8px;
    gap: 12px;
  }

  .practice {
    padding: 12px;
  }

  .canvas-wrap {
    width: min(100%, clamp(210px, 31vh, 330px));
  }

  .hero-text h1 {
    font-size: clamp(1.9rem, 3.8vw, 3.1rem);
  }

  .auth-card {
    padding: 8px;
  }
}

@media (min-width: 901px) {
  html,
  body {
    height: 100%;
  }

  body {
    overflow: hidden;
  }

  .app {
    height: 100vh;
    display: flex;
    flex-direction: column;
  }

  .layout {
    flex: 1;
    min-height: 0;
  }

  .practice {
    height: 100%;
    overflow: auto;
  }
}
