:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #667085;
  --line: #d7dee8;
  --paper: #ffffff;
  --wash: #f4f7fb;
  --accent: #d34236;
  --accent-dark: #a92e27;
  --teal: #197b78;
  --shadow: 0 16px 38px rgba(38, 48, 72, 0.13);
  --kana-hand-font: "Yu Gothic", "Yu Gothic UI", "Meiryo", "Hiragino Maru Gothic ProN", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Inter", "Noto Sans SC", "Microsoft YaHei", "Yu Gothic", sans-serif;
  background: #eef3f8;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 0 10px calc(28px + env(safe-area-inset-bottom));
}

.phone-app {
  width: min(430px, 100%);
  margin: 0 auto;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  gap: 8px;
  margin: 0 -10px 10px;
  padding: 10px;
  border-bottom: 1px solid rgba(215, 222, 232, 0.9);
  background: rgba(238, 243, 248, 0.94);
  backdrop-filter: blur(14px);
}

.eyebrow,
h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin-top: 2px;
  font-size: 1.55rem;
  line-height: 1;
}

.script-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}

.script-button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-weight: 900;
}

.script-button.active {
  color: white;
  background: var(--ink);
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.filters label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 10px;
  color: var(--ink);
  background: white;
  font-size: 0.94rem;
  font-weight: 800;
}

.test-card,
.canvas-card,
.hint-panel,
.score-panel,
.wrong-panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.test-card {
  width: min(100%, 360px);
  margin-bottom: 8px;
  margin-left: auto;
  margin-right: auto;
  padding: 8px 10px;
  color: white;
  background: linear-gradient(135deg, #202124, #197b78);
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#questionMeta {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.72rem;
  font-weight: 900;
}

.round-button {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  color: var(--ink);
  background: white;
  font-weight: 900;
}

.prompt-label {
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.72rem;
  font-weight: 800;
}

.romaji-prompt {
  margin-top: 0;
  font-size: clamp(2.1rem, 11vw, 3.2rem);
  font-weight: 950;
  line-height: 0.92;
}

.judge-feedback {
  min-height: 18px;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.72rem;
  font-weight: 800;
}

.judge-feedback.good {
  color: #baf3df;
}

.judge-feedback.bad {
  color: #ffd0ca;
}

.canvas-card {
  position: relative;
  overflow: hidden;
  width: min(100%, 390px);
  margin: 0 auto;
}

.clear-float {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(211, 66, 54, 0.28);
  border-radius: 50%;
  color: var(--accent-dark);
  background: rgba(255, 240, 238, 0.94);
  box-shadow: 0 8px 18px rgba(38, 48, 72, 0.12);
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1;
}

.clear-float.hidden {
  display: none;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  touch-action: none;
  background: #fffdf9;
}

.canvas-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--wash);
}

.tool-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: white;
  font-weight: 950;
}

.tool-button.hint {
  border-color: rgba(211, 66, 54, 0.35);
  color: var(--accent-dark);
  background: #fff0ee;
}

.tool-button.judge {
  border-color: var(--teal);
  color: white;
  background: var(--teal);
}

.hint-panel {
  margin-top: 10px;
  padding: 12px;
}

.hint-panel.hidden {
  display: none;
}

.answer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.answer-row span {
  color: var(--muted);
  font-weight: 900;
}

.answer-row strong {
  font-family: var(--kana-hand-font);
  font-weight: 500;
  font-size: 4.2rem;
  line-height: 1;
}

.stroke-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 10px;
}

.stroke-head h2 {
  font-size: 1rem;
}

#strokeCount {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  color: var(--teal);
  background: rgba(25, 123, 120, 0.1);
  font-size: 0.78rem;
  font-weight: 900;
}

.stroke-steps {
  display: grid;
  gap: 8px;
}

.stroke-step {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 9px;
  align-items: start;
  padding: 10px;
  border: 1px solid #e7edf4;
  border-radius: 10px;
  background: var(--wash);
}

.stroke-step span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: white;
  background: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
}

.stroke-step p {
  color: #344054;
  font-size: 0.9rem;
  line-height: 1.45;
}

.score-panel {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin-top: 10px;
  overflow: hidden;
}

.score-panel div {
  display: grid;
  gap: 4px;
  place-items: center;
  min-height: 58px;
  background: white;
}

.score-panel span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.score-panel strong {
  font-size: 1.2rem;
}

.wrong-panel {
  margin-top: 12px;
  padding: 14px;
}

.wrong-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.wrong-head h2 {
  font-size: 1rem;
}

.wrong-head button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: white;
  font-size: 0.8rem;
  font-weight: 900;
}

.wrong-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
}

.wrong-empty {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.wrong-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid #ffd4ce;
  border-radius: 999px;
  color: var(--accent-dark);
  background: #fff0ee;
  font-weight: 900;
}

.wrong-chip strong {
  font-family: var(--kana-hand-font);
  font-weight: 600;
  font-size: 1.2rem;
}

.wrong-chip span {
  font-size: 0.82rem;
}

@media (min-width: 800px) {
  .app-shell {
    padding-top: 18px;
  }

  .app-header {
    border: 1px solid var(--line);
    border-radius: 14px;
    margin: 0 0 12px;
  }
}

@media (max-width: 520px) {
  .hint-panel,
  .score-panel,
  .wrong-panel {
    width: min(100%, 390px);
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 380px) {
  h1 {
    font-size: 1.4rem;
  }

  .romaji-prompt {
    font-size: 3.4rem;
  }

  .answer-row strong {
    font-size: 3.4rem;
  }

  .score-panel {
    grid-template-columns: repeat(2, 1fr);
  }
}
