* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Work Sans", sans-serif;
  color: #1d1b18;
  background: #faf6ee;
  overflow: hidden;
}

body {
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
}

.dojo {
  position: relative;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
  background: #faf6ee;
}
.dojo:fullscreen,
.dojo:-webkit-full-screen {
  background: #faf6ee;
}
.dojo::backdrop {
  background: #faf6ee;
}

.topbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px clamp(18px, 4vw, 48px) 0;
  pointer-events: none;
}
.topbar .brand {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 700;
  font-size: clamp(1.05rem, 2vw, 1.4rem);
  letter-spacing: 0.02em;
  color: #1d1b18;
}
.topbar .brand span {
  color: #a89f8f;
  font-family: "Work Sans", sans-serif;
  font-weight: 500;
  font-size: 0.6em;
  display: block;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-top: 2px;
}
.topbar .topbar-right {
  display: flex;
  align-items: center;
  gap: clamp(14px, 3vw, 26px);
}
.topbar .stats {
  display: flex;
  gap: clamp(16px, 3vw, 34px);
  text-align: right;
}
.topbar .stats .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.topbar .stats .stat .stat-label {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #a89f8f;
}
.topbar .stats .stat .stat-value {
  font-family: "Shippori Mincho B1", serif;
  font-weight: 700;
  font-size: clamp(1.2rem, 2.6vw, 1.6rem);
  font-variant-numeric: tabular-nums;
  color: #1d1b18;
  transition: transform 0.25s ease;
}
.topbar .stats .stat .stat-value.bump {
  transform: scale(1.18);
}
.topbar .sound-toggle {
  pointer-events: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(36px, 6vw, 42px);
  height: clamp(36px, 6vw, 42px);
  border-radius: 50%;
  border: 1px solid rgba(29, 27, 24, 0.14);
  background: rgba(240, 233, 216, 0.6);
  color: #6b6459;
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.topbar .sound-toggle .icon {
  display: block;
  width: 18px;
  height: 18px;
}
.topbar .sound-toggle .icon-off {
  display: none;
}
.topbar .sound-toggle:hover {
  color: #1d1b18;
  border-color: rgba(29, 27, 24, 0.28);
}
.topbar .sound-toggle:focus-visible {
  outline: 3px solid #b8933e;
  outline-offset: 2px;
}
.topbar .sound-toggle.is-muted .icon-on {
  display: none;
}
.topbar .sound-toggle.is-muted .icon-off {
  display: block;
}
.topbar .sound-toggle.is-muted {
  color: #c9584b;
  border-color: rgba(178, 58, 46, 0.3);
}
.topbar .sound-toggle.is-unavailable {
  opacity: 0.35;
  cursor: not-allowed;
}

.field {
  position: relative;
  flex: 1;
  display: flex;
  overflow: hidden;
}

.zone {
  position: relative;
  flex: 1;
  height: 100%;
  border: none;
  background: none;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.zone:focus-visible {
  outline: 3px solid #b8933e;
  outline-offset: -6px;
}
.zone .zone-fill {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity 0.22s ease;
}
.zone:hover .zone-fill, .zone:active .zone-fill {
  opacity: 1;
}
.zone .zone-label {
  position: absolute;
  bottom: clamp(22px, 5vh, 46px);
  font-family: "Shippori Mincho B1", serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: clamp(1.1rem, 2.4vw, 1.6rem);
  color: #a89f8f;
  user-select: none;
}
.zone .zone-label small {
  display: block;
  font-family: "Work Sans", sans-serif;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.42em;
  margin-top: 6px;
  color: #a89f8f;
}

.zone--hira .zone-fill {
  background: radial-gradient(circle at 30% 70%, rgba(34, 64, 108, 0.26), transparent 68%);
}
.zone--hira .zone-label {
  left: clamp(22px, 6vw, 64px);
  text-align: left;
}
.zone--hira::before {
  content: "";
  position: absolute;
  pointer-events: none;
  left: -8%;
  bottom: -12%;
  width: 46vw;
  height: 46vw;
  max-width: 480px;
  max-height: 480px;
  border-radius: 62% 38% 55% 45%/55% 45% 55% 45%;
  background: linear-gradient(135deg, rgba(34, 64, 108, 0.08), rgba(34, 64, 108, 0.02));
  filter: blur(1px);
}

.zone--kata .zone-fill {
  background: radial-gradient(circle at 70% 70%, rgba(178, 58, 46, 0.26), transparent 68%);
}
.zone--kata .zone-label {
  right: clamp(22px, 6vw, 64px);
  text-align: right;
}
.zone--kata::before {
  content: "";
  position: absolute;
  pointer-events: none;
  right: -6%;
  bottom: -10%;
  width: 40vw;
  height: 40vw;
  max-width: 420px;
  max-height: 420px;
  clip-path: polygon(20% 0%, 100% 10%, 85% 60%, 100% 100%, 30% 90%, 0% 55%);
  background: linear-gradient(135deg, rgba(178, 58, 46, 0.09), rgba(178, 58, 46, 0.02));
}

.brush-divider {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 100%;
  width: clamp(60px, 8vw, 120px);
  z-index: 20;
  pointer-events: none;
}
.brush-divider svg {
  height: 100%;
  width: 100%;
}
.brush-divider path {
  stroke: #1d1b18;
  stroke-width: 2.5;
  fill: none;
  opacity: 0.16;
  stroke-linecap: round;
  stroke-dasharray: 1400;
  stroke-dashoffset: 1400;
  animation: draw-stroke 1.4s cubic-bezier(0.65, 0, 0.35, 1) forwards 0.2s;
}

@keyframes draw-stroke {
  to {
    stroke-dashoffset: 0;
  }
}
.kana-stage {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  pointer-events: none;
}

.kana-card {
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(150px, 26vw, 230px);
  height: clamp(150px, 26vw, 230px);
  border-radius: 50%;
  background: #faf6ee;
  box-shadow: 0 0 0 1px rgba(29, 27, 24, 0.06), 0 18px 50px -12px rgba(29, 27, 24, 0.28);
}
.kana-card .kana-glyph {
  font-family: "Noto Sans JP", sans-serif;
  font-weight: 700;
  font-size: clamp(4.4rem, 10.5vw, 7.6rem);
  line-height: 1;
  color: #1d1b18;
  user-select: none;
  transition: transform 0.18s ease, color 0.18s ease;
}
.kana-card.is-correct {
  animation: stamp-correct 0.42s ease;
}
.kana-card.is-correct .kana-glyph {
  color: #b8933e;
}
.kana-card.is-wrong {
  animation: shake-wrong 0.42s ease;
}
.kana-card.is-wrong .kana-glyph {
  color: #c97870;
}

@keyframes stamp-correct {
  0% {
    transform: scale(1);
  }
  35% {
    transform: scale(1.14);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes shake-wrong {
  0%, 100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-10px);
  }
  40% {
    transform: translateX(9px);
  }
  60% {
    transform: translateX(-6px);
  }
  80% {
    transform: translateX(4px);
  }
}
.pronounce-btn {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(29, 27, 24, 0.14);
  background: rgba(250, 246, 238, 0.9);
  color: #6b6459;
  font-family: "Work Sans", sans-serif;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, transform 0.15s ease;
}
.pronounce-btn .icon {
  display: block;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}
.pronounce-btn:hover {
  color: #1d1b18;
  border-color: rgba(29, 27, 24, 0.3);
}
.pronounce-btn:active {
  transform: scale(0.96);
}
.pronounce-btn:focus-visible {
  outline: 3px solid #b8933e;
  outline-offset: 2px;
}
.pronounce-btn.is-unavailable {
  opacity: 0.35;
  cursor: not-allowed;
}
.pronounce-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  color: #a89f8f;
  border-color: rgba(29, 27, 24, 0.08);
  background: rgba(240, 233, 216, 0.55);
}

.feedback {
  position: absolute;
  top: calc(46% + clamp(150px, 21vw, 200px));
  left: 50%;
  transform: translate(-50%, 6px);
  z-index: 25;
  font-size: clamp(1rem, 2.4vw, 1.15rem);
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: rgba(250, 246, 238, 0);
  box-shadow: 0 10px 30px -18px rgba(29, 27, 24, 0);
  text-align: center;
  letter-spacing: 0.03em;
  color: #6b6459;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease, background 0.28s ease, border-color 0.28s ease, box-shadow 0.28s ease;
}
.feedback.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
.feedback strong {
  color: #1d1b18;
  font-weight: 700;
}

.hint {
  position: relative;
  z-index: 30;
  text-align: center;
  padding: 0 20px 18px;
  font-size: clamp(0.85rem, 2vw, 0.95rem);
  letter-spacing: 0.04em;
  color: #a89f8f;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .brush-divider path {
    animation: none;
    opacity: 0.16;
    stroke-dashoffset: 0;
  }
  .kana-card.is-correct,
  .kana-card.is-wrong,
  .stat-value.bump {
    animation: none !important;
  }
}
@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
  }
  .zone-label {
    bottom: clamp(16px, 4vh, 28px);
    font-size: clamp(1rem, 5.5vw, 1.3rem);
  }
  .zone-label small {
    font-size: 0.46em;
  }
  .zone--hira .zone-label {
    left: 16px;
  }
  .zone--kata .zone-label {
    right: 16px;
  }
  .kana-card {
    width: clamp(130px, 34vw, 180px);
    height: clamp(130px, 34vw, 180px);
  }
  .kana-card .kana-glyph {
    font-size: clamp(3.2rem, 16vw, 4.6rem);
  }
}
.feedback.feedback--correct {
  border-color: rgba(79, 127, 96, 0.18);
  background: #eaf1ec;
  box-shadow: 0 10px 30px -18px rgba(79, 127, 96, 0.35);
}
.feedback.feedback--wrong {
  border-color: rgba(178, 58, 46, 0.15);
  background: #f5e9e7;
  box-shadow: 0 10px 30px -18px rgba(178, 58, 46, 0.3);
}

/* Options, romanisation et mise en page plein écran */
.topbar .settings-wrap { position: relative; pointer-events: auto; }
.topbar .settings-toggle { pointer-events: auto; flex-shrink: 0; display: flex; align-items: center; justify-content: center; width: clamp(36px, 6vw, 42px); height: clamp(36px, 6vw, 42px); border-radius: 50%; border: 1px solid rgba(29, 27, 24, 0.14); background: rgba(240, 233, 216, 0.6); color: #6b6459; cursor: pointer; transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease; }
.topbar .settings-toggle > svg { display: block; width: 19px; height: 19px; transition: transform 0.25s ease; }
.topbar .settings-toggle:hover, .topbar .settings-toggle.is-open { color: #1d1b18; border-color: rgba(29, 27, 24, 0.3); }
.topbar .settings-toggle:focus-visible { outline: 3px solid #b8933e; outline-offset: 2px; }
.topbar .settings-toggle.is-open > svg { transform: rotate(35deg); }
.topbar .settings-panel { position: absolute; top: calc(100% + 10px); right: 0; width: min(260px, calc(100vw - 28px)); padding: 16px; border: 1px solid rgba(29, 27, 24, 0.12); border-radius: 14px; background: rgba(250, 246, 238, 0.98); box-shadow: 0 14px 38px -14px rgba(29, 27, 24, 0.3); color: #6b6459; }
.topbar .settings-panel[hidden] { display: none; }
.topbar .settings-panel strong { display: block; margin-bottom: 10px; color: #1d1b18; font-size: 0.82rem; letter-spacing: 0.05em; }
.topbar .settings-panel label { display: flex; align-items: center; gap: 9px; padding: 6px 0; font-size: 0.82rem; cursor: pointer; }
.topbar .settings-panel label span { margin-left: auto; font-family: "Noto Sans JP", sans-serif; color: #a89f8f; }
.topbar .settings-panel .option-example { font-size: 1.25rem; line-height: 1; }
.topbar .settings-panel .option-example--mark { font-size: 1.8rem; line-height: 0.7; }
.topbar .settings-panel input { width: 17px; height: 17px; accent-color: #22406c; }
.topbar .settings-panel hr { margin: 9px 0; border: 0; border-top: 1px solid rgba(29, 27, 24, 0.1); }
.kana-card { flex-direction: column; }
.kana-card .kana-glyph.is-combination { font-size: clamp(3.5rem, 8vw, 6rem); }
.kana-card .kana-romaji { margin-top: 8px; font-family: "Work Sans", sans-serif; font-size: 1rem; font-weight: 700; letter-spacing: 0.16em; color: #a89f8f; }
.hint { position: absolute; top: clamp(76px, 10vh, 94px); left: 50%; transform: translateX(-50%); width: 100%; margin: 0; padding: 0 20px; }
@media (max-width: 640px) {
  .kana-card .kana-glyph.is-combination { font-size: clamp(2.7rem, 12vw, 3.8rem); }
  .hint { top: 72px; font-size: clamp(0.7rem, 3vw, 0.85rem); }
}
@media (max-width: 480px) {
  .topbar { padding-top: 14px; }
  .topbar .brand span { display: none; }
  .topbar .topbar-right { gap: 8px; }
  .topbar .stats { gap: 9px; }
  .topbar .stats .stat-label { font-size: 0.52rem; }
  .topbar .sound-toggle, .topbar .settings-toggle { width: 34px; height: 34px; }
  .hint { top: 62px; }
}
@media (max-height: 560px) {
  .hint { top: 58px; font-size: 0.72rem; }
  .kana-stage { top: 48%; gap: 8px; }
  .kana-card { width: 122px; height: 122px; }
  .kana-card .kana-glyph { font-size: 3.3rem; }
  .kana-card .kana-glyph.is-combination { font-size: 2.7rem; }
  .zone .zone-label { bottom: 12px; }
}

/* Améliorations d'interface */
.topbar .fullscreen-toggle { pointer-events: auto; flex-shrink: 0; display: flex; align-items: center; justify-content: center; width: clamp(36px, 6vw, 42px); height: clamp(36px, 6vw, 42px); border-radius: 50%; border: 1px solid rgba(29, 27, 24, 0.14); background: rgba(240, 233, 216, 0.6); color: #6b6459; cursor: pointer; transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease; }
.topbar .fullscreen-toggle svg { display: block; width: 18px; height: 18px; }
.topbar .fullscreen-toggle:hover { color: #1d1b18; border-color: rgba(29, 27, 24, 0.28); }
.topbar .fullscreen-toggle:focus-visible { outline: 3px solid #b8933e; outline-offset: 2px; }
.topbar .fullscreen-toggle .fullscreen-exit { display: none; }
.topbar .fullscreen-toggle.is-active .fullscreen-enter { display: none; }
.topbar .fullscreen-toggle.is-active .fullscreen-exit { display: block; }
.zone .zone-label { font-size: clamp(1.35rem, 3vw, 2rem); }
.hint strong { position: relative; z-index: 1; }
.hint::before { content: ""; position: absolute; z-index: -1; top: -7px; bottom: -7px; left: 50%; width: min(570px, calc(100% - 24px)); transform: translateX(-50%); border-radius: 999px; background: rgba(250, 246, 238, 0.94); }
.orientation-tip { display: none; }
@media (max-width: 480px) {
  .topbar .fullscreen-toggle { width: 34px; height: 34px; }
}
@media (max-width: 800px) and (orientation: portrait) {
  .orientation-tip { position: fixed; z-index: 50; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); left: 12px; display: flex; align-items: center; gap: 9px; padding: 10px 38px 10px 12px; border: 1px solid rgba(29, 27, 24, 0.12); border-radius: 14px; background: rgba(250, 246, 238, 0.97); box-shadow: 0 12px 35px -14px rgba(29, 27, 24, 0.4); color: #6b6459; font-size: 0.75rem; }
  .orientation-tip.is-dismissed { display: none; }
  .orientation-tip .rotate-icon { font-size: 1.35rem; color: #22406c; }
  .orientation-tip button { flex-shrink: 0; padding: 6px 9px; border: 0; border-radius: 999px; background: #22406c; color: white; font-size: 0.7rem; cursor: pointer; }
  .orientation-tip .tip-close { position: absolute; right: 5px; padding: 4px 8px; background: transparent; color: #a89f8f; font-size: 1.2rem; }
}
