:root {
  color-scheme: light;
  --ink: #17242a;
  --muted: #52646c;
  --paper: #ffffff;
  --wash: #f7fbff;
  --line: #cfe0e6;
  --teal: #1c6b6b;
  --teal-dark: #125252;
  --blue: #2f80ed;
  --green: #2f9e74;
  --amber: #f2c94c;
  --coral: #e76f51;
  --danger: #c24132;
  --shadow: 0 8px 20px rgba(23, 36, 42, 0.08);
  --radius: 8px;
  --tap: 60px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--wash);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Meiryo", system-ui, sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
}

button {
  min-height: var(--tap);
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 4px solid rgba(47, 128, 237, 0.45);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app {
  min-height: 100dvh;
}

.app-shell {
  width: min(1180px, calc(100vw - 28px));
  min-height: 0;
  margin: 0 auto;
  padding: 10px 0 18px;
}

.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  margin-bottom: 10px;
}

.topbar img {
  width: 46px;
  height: 46px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(28px, 3.4vw, 40px);
  line-height: 1;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: clamp(14px, 1.4vw, 17px);
}

.play-shell {
  padding-top: 7px;
  padding-bottom: 7px;
}

.play-shell .topbar {
  min-height: 44px;
  margin-bottom: 5px;
}

.play-shell .topbar img {
  width: 36px;
  height: 36px;
}

.play-shell .topbar h1 {
  font-size: clamp(23px, 2.4vw, 30px);
}

.play-shell .topbar p {
  display: none;
}

.ghost,
.secondary,
.danger-button {
  padding: 0 18px;
  color: var(--teal-dark);
  background: #e4f4f1;
  font-weight: 800;
}

.primary {
  padding: 0 22px;
  color: #ffffff;
  background: var(--teal);
  font-weight: 900;
}

.primary:hover {
  background: var(--teal-dark);
}

.danger-button {
  width: 100%;
  color: #ffffff;
  background: var(--danger);
}

.danger-button:disabled {
  color: var(--muted);
  background: #e6eef1;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: end;
  gap: 8px;
}

.top-actions .ghost {
  min-height: 48px;
  padding: 0 14px;
}

.user-pill {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  max-width: 150px;
  padding: 0 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--teal-dark);
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.center-screen {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
  font-size: 22px;
}

.error-text {
  color: var(--danger);
}

.auth-shell {
  display: grid;
  place-items: start center;
  min-height: 100vh;
  min-height: 100svh;
  padding: clamp(14px, 3vh, 28px) 18px 18px;
}

.auth-card {
  width: min(900px, 100%);
  padding: clamp(18px, 2.6vw, 30px);
  border: 1px solid var(--line);
  border-top: 8px solid var(--teal);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.setup-card {
  width: min(620px, 100%);
  text-align: center;
}

.setup-card > img {
  width: 76px;
  height: 76px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-card h1,
.auth-card h2,
.auth-card p {
  margin: 0;
}

.auth-card h1 {
  margin-top: 8px;
  font-size: clamp(34px, 5vw, 52px);
}

.auth-card p {
  color: var(--muted);
  font-size: clamp(15px, 1.7vw, 19px);
  line-height: 1.55;
}

.auth-head {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.auth-head img {
  width: 64px;
  height: 64px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-head h1 {
  margin: 0;
}

.auth-form {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 900;
  text-align: left;
}

.auth-form input {
  width: 100%;
  min-height: 58px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #ffffff;
  font: inherit;
  font-size: clamp(18px, 2vw, 24px);
  font-weight: 900;
}

.auth-form input:focus {
  outline: 4px solid rgba(47, 128, 237, 0.24);
  border-color: var(--blue);
}

.inline-auth,
.add-user-form,
.manage-user-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.account-panels {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #e6f0f3;
}

.add-user-form,
.manage-user-form {
  margin-top: 10px;
}

.user-select {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.user-tile {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 76px;
  padding: 10px;
  border: 2px solid var(--line);
  background: #ffffff;
  text-align: center;
}

.user-tile.active {
  border-color: var(--teal);
  background: #e8f7f4;
  color: var(--teal-dark);
}

.user-tile strong {
  max-width: 100%;
  overflow: hidden;
  font-size: clamp(18px, 2vw, 25px);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-tile span,
.user-tile small,
.auth-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.user-tile small {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-message {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #fff6d8;
  color: #68520b;
  font-weight: 900;
}

.add-user-panel h2,
.user-admin-panel h2 {
  font-size: clamp(20px, 2.2vw, 28px);
}

.delete-user-form {
  margin-top: 10px;
}

.auth-note {
  margin-top: 10px;
}

.home-grid {
  display: grid;
  grid-template-columns: 1.16fr 0.84fr;
  gap: 14px;
}

.home-status,
.mode-button,
.menu-screen,
.word-menu,
.result-screen {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.home-status {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 16px;
  border-top: 8px solid var(--coral);
}

.home-status div {
  display: grid;
  align-items: center;
  gap: 4px;
  min-height: 72px;
  padding: 8px;
  border-radius: var(--radius);
  background: #f7fbff;
}

.home-status span {
  color: var(--muted);
  font-weight: 800;
}

.home-status strong {
  font-size: clamp(20px, 2.3vw, 28px);
  line-height: 1.1;
}

.mode-button {
  display: grid;
  justify-items: start;
  gap: 8px;
  min-height: 150px;
  padding: clamp(19px, 2.5vw, 28px);
  text-align: left;
  border-top: 8px solid var(--blue);
}

.mode-button.words {
  border-top-color: var(--green);
}

.mode-button strong {
  font-size: clamp(27px, 3.2vw, 39px);
}

.mode-button span {
  color: var(--muted);
  font-size: clamp(16px, 1.7vw, 20px);
}

.ranking-panel {
  grid-column: 1 / -1;
  padding: 14px;
  border: 1px solid var(--line);
  border-top: 8px solid var(--amber);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: var(--shadow);
}

.ranking-panel > header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 10px;
}

.ranking-panel h2,
.ranking-panel h3,
.ranking-panel p {
  margin: 0;
}

.ranking-panel h2 {
  font-size: clamp(23px, 2.6vw, 32px);
}

.ranking-panel header p,
.ranking-list p {
  color: var(--muted);
  font-size: clamp(13px, 1.35vw, 16px);
  font-weight: 800;
}

.ranking-panel header > span {
  display: inline-grid;
  place-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: var(--radius);
  background: #fff6d8;
  color: #6c5410;
  font-weight: 900;
}

.ranking-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.ranking-list {
  min-width: 0;
  padding: 10px;
  border: 1px solid #e6f0f3;
  border-radius: var(--radius);
}

.ranking-list h3 {
  font-size: clamp(17px, 1.8vw, 22px);
}

.ranking-list ol {
  display: grid;
  gap: 6px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.ranking-list li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 5px 8px;
  border-radius: var(--radius);
  background: #f7fbff;
}

.ranking-list li > span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--teal);
  color: #ffffff;
  font-weight: 900;
}

.ranking-list strong {
  display: grid;
  gap: 1px;
  overflow: hidden;
  font-size: clamp(15px, 1.7vw, 20px);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-list small {
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(11px, 1.15vw, 13px);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-list em {
  color: var(--muted);
  font-size: clamp(13px, 1.35vw, 16px);
  font-style: normal;
  font-weight: 900;
  white-space: nowrap;
}

.menu-screen,
.word-menu,
.result-screen {
  padding: clamp(14px, 2vw, 24px);
}

.word-menu {
  display: grid;
  grid-template-rows: auto auto auto;
}

.screen-title {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
}

.screen-title.compact {
  grid-template-columns: auto 1fr;
  align-items: end;
  column-gap: 18px;
}

.screen-title h2 {
  margin: 0;
  font-size: clamp(30px, 3.5vw, 42px);
}

.screen-title p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(15px, 1.6vw, 19px);
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.level-tile,
.option {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 84px;
  padding: 10px;
  border: 2px solid var(--line);
  background: #ffffff;
  text-align: center;
  font-weight: 800;
}

.level-tile strong,
.option strong {
  font-size: clamp(22px, 2.4vw, 30px);
}

.level-tile span,
.option span {
  color: var(--muted);
  font-size: clamp(12px, 1.3vw, 15px);
  line-height: 1.28;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.setting-panel {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.setting-panel h3 {
  margin: 0;
  font-size: clamp(18px, 2vw, 24px);
}

.option-stack {
  display: grid;
  gap: 8px;
  align-content: start;
}

.option.active {
  border-color: var(--teal);
  background: #e8f7f4;
  color: var(--teal-dark);
}

.start-band {
  display: grid;
  grid-template-columns: 1fr minmax(170px, 250px);
  gap: 12px;
  align-items: center;
  margin-top: 13px;
  padding: 13px;
  border-radius: var(--radius);
  background: #eef8f6;
}

.start-band strong,
.start-band span {
  display: block;
}

.start-band strong {
  font-size: clamp(20px, 2.2vw, 28px);
}

.start-band span {
  margin-top: 4px;
  color: var(--muted);
  font-weight: 800;
}

.play-hud {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  margin-bottom: 5px;
}

.play-hud h2 {
  margin: 0 auto 0 0;
  font-size: clamp(22px, 2.4vw, 30px);
}

.play-hud span {
  display: inline-flex;
  align-items: center;
  min-height: 33px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.thin-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #dbe9ee;
}

.thin-progress span {
  display: block;
  width: var(--value);
  height: 100%;
  background: var(--teal);
}

.number-board {
  position: relative;
  height: clamp(420px, 70dvh, 650px);
  margin-top: 8px;
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(#eaf3f7 1px, transparent 1px),
    linear-gradient(90deg, #eaf3f7 1px, transparent 1px),
    #ffffff;
  background-size: 64px 64px;
}

.number-dot {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: clamp(58px, 6vw, 78px);
  height: clamp(58px, 6vw, 78px);
  min-height: 0;
  transform: translate(-50%, -50%);
  border: 3px solid #d5e5eb;
  background: #ffffff;
  box-shadow: 0 8px 16px rgba(23, 36, 42, 0.1);
  font-size: clamp(24px, 3.4vw, 40px);
  font-weight: 900;
}

.number-dot.done {
  color: #ffffff;
  border-color: var(--green);
  background: var(--green);
  box-shadow: none;
}

.number-dot.wrong {
  border-color: var(--danger);
  background: #fff0ed;
}

.word-play.preview {
  display: grid;
  grid-template-rows: auto auto auto auto;
  min-height: 0;
}

.preview-card {
  --rule-color: rgba(38, 115, 112, 0.13);
  --rule-step: clamp(44px, 5vw, 64px);
  display: grid;
  place-items: center;
  height: clamp(360px, 68dvh, 650px);
  min-height: 0;
  margin-top: 8px;
  padding: clamp(16px, 2.6vw, 32px);
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background-color: #ffffff;
  background-image: none;
  text-align: center;
}

.preview-card.horizontal {
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--rule-step) - 1px),
    var(--rule-color) calc(var(--rule-step) - 1px),
    var(--rule-color) var(--rule-step)
  );
}

.preview-card.vertical {
  background-image: repeating-linear-gradient(
    to right,
    transparent 0,
    transparent calc(var(--rule-step) - 1px),
    var(--rule-color) calc(var(--rule-step) - 1px),
    var(--rule-color) var(--rule-step)
  );
}

.preview-card.grade-2 {
  --rule-step: clamp(42px, 4.6vw, 58px);
}

.preview-card.grade-3 {
  --rule-step: clamp(38px, 4vw, 52px);
}

.chunk-text {
  display: block;
  max-width: 1020px;
  font-size: clamp(29px, 4.1vw, 50px);
  font-weight: 900;
  line-height: 1.48;
}

.chunk-text span {
  display: inline;
}

.preview-card.grade-2 .chunk-text {
  font-size: clamp(27px, 3.3vw, 42px);
  line-height: 1.58;
}

.preview-card.grade-3 .chunk-text {
  font-size: clamp(23px, 2.55vw, 33px);
  line-height: 1.68;
}

.preview-card.vertical .chunk-text {
  display: inline-block;
  max-width: 100%;
  max-height: 100%;
  writing-mode: vertical-rl;
  text-orientation: upright;
  text-align: start;
}

.preview-card.vertical .chunk-text span {
  display: inline;
}

.preview-card.vertical.grade-2 .chunk-text {
  font-size: clamp(25px, 2.9vw, 36px);
}

.preview-card.vertical.grade-3 .chunk-text {
  font-size: clamp(22px, 2.25vw, 30px);
  line-height: 1.78;
}

.training-tip {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: clamp(15px, 1.7vw, 19px);
  font-weight: 900;
  text-align: center;
}

.word-play.answer {
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  min-height: 0;
}

.answer-card {
  display: grid;
  grid-template-rows: auto auto auto auto;
  align-self: start;
  gap: 9px;
  min-height: 0;
  margin-top: 8px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.recall-line {
  display: grid;
  place-items: center;
  min-height: 52px;
  margin: 0;
  border-radius: var(--radius);
  background: #eef8f6;
  color: var(--teal-dark);
  font-size: clamp(20px, 2.1vw, 28px);
  font-weight: 900;
  text-align: center;
}

.answer-card h3 {
  margin: 0;
  font-size: clamp(21px, 2.4vw, 30px);
  line-height: 1.25;
  text-align: center;
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-height: 0;
}

.answer-choice {
  min-height: clamp(68px, 9dvh, 88px);
  padding: 10px 14px;
  border: 2px solid var(--line);
  background: #ffffff;
  font-size: clamp(17px, 1.95vw, 24px);
  font-weight: 900;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.answer-choice.correct {
  color: #ffffff;
  border-color: var(--green);
  background: var(--green);
}

.answer-choice.incorrect {
  color: #ffffff;
  border-color: var(--danger);
  background: var(--danger);
}

.feedback {
  min-height: 30px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(15px, 1.5vw, 18px);
  font-weight: 900;
  text-align: center;
}

.result-screen {
  max-width: 900px;
  margin: 0 auto;
  border-top: 8px solid var(--amber);
}

.result-screen h2 {
  margin: 0;
  font-size: clamp(30px, 3.8vw, 44px);
}

.result-screen p {
  margin: 10px 0 16px;
  color: var(--muted);
  font-size: clamp(17px, 1.8vw, 21px);
  line-height: 1.55;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.result-grid div {
  min-height: 94px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.result-grid span,
.result-grid strong {
  display: block;
}

.result-grid span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.result-grid strong {
  margin-top: 8px;
  font-size: clamp(22px, 2.6vw, 32px);
  line-height: 1.12;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 20px, 800px);
  }

  .topbar {
    grid-template-columns: auto 1fr auto;
  }

  .screen-title.compact {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    gap: 9px;
  }

  .level-tile,
  .option {
    min-height: 66px;
    padding: 8px;
  }

  .option strong {
    font-size: clamp(19px, 2.5vw, 25px);
  }

  .option span {
    font-size: clamp(11px, 1.55vw, 14px);
  }

  .home-grid,
  .result-grid {
    grid-template-columns: 1fr;
  }

  .level-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .user-select {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (orientation: portrait) and (min-width: 621px) and (max-width: 900px) {
  .settings-grid {
    grid-template-columns: 1.08fr 0.92fr 0.8fr;
  }
}

@media (max-width: 620px) {
  :root {
    --tap: 56px;
  }

  .topbar {
    grid-template-columns: auto 1fr;
  }

  .topbar .top-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .top-actions .ghost,
  .top-actions .user-pill {
    flex: 1;
  }

  .settings-grid,
  .start-band,
  .button-row,
  .account-panels,
  .inline-auth,
  .add-user-form,
  .manage-user-form,
  .ranking-grid {
    grid-template-columns: 1fr;
  }

  .level-grid,
  .answer-grid,
  .user-select {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .play-hud {
    flex-wrap: wrap;
  }
}

@media (max-width: 440px) {
  .level-grid,
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .topbar img {
    width: 42px;
    height: 42px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
