:root {
  --accent: #2a55e0;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  font-family: "YuGothic", "Yu Gothic Medium", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  color: var(--text);
  background: #f8fafc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 16px;
  flex: 1;
}

h1 {
  margin: 0;
  font-size: 1.75rem;
}

.lead {
  margin: 8px 0 24px;
  color: var(--muted);
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}

label {
  display: block;
  font-weight: 700;
  margin-bottom: 8px;
}

textarea {
  width: 100%;
  padding: 12px;
  font: inherit;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  resize: vertical;
}

textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-color: var(--accent);
}

.result strong {
  color: var(--accent);
  font-size: 1.25rem;
}

.footer {
  padding: 24px 16px;
  text-align: center;
  font-size: 0.875rem;
}

.footer a {
  color: var(--muted);
}

.footer a + a {
  margin-left: 1.25em;
}

/* --- Typing Challenge --- */
.container {
  max-width: 760px;
}

main > section + section {
  margin-top: 16px;
}

h2 {
  margin: 0;
  font-size: 1.1rem;
}

.hint {
  margin: 12px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0;
  padding: 12px 20px;
  font: inherit;
  font-weight: 700;
  color: var(--accent);
  background: #fff;
  border: 1px solid var(--accent);
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
}

button.primary {
  color: #fff;
  background: var(--accent);
}

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

button.link {
  padding: 8px;
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--muted);
  background: none;
  border: 0;
  text-decoration: underline;
}

.kbd {
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: 400;
  border: 1px solid currentColor;
  border-radius: 4px;
  opacity: 0.75;
}

@media (pointer: coarse) {
  .kbd {
    display: none;
  }
}

/* スタート */
#screen-start {
  text-align: center;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.mode-switch label {
  margin: 0;
}

.mode-switch input {
  position: absolute;
  opacity: 0;
}

.mode-switch span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 8px;
  font-size: 1.1rem;
  border: 2px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
}

.mode-switch small {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

.mode-switch input:checked + span {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, #fff);
}

.mode-switch input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.big {
  width: 100%;
  padding: 16px;
  font-size: 1.2rem;
}

.best {
  margin: 12px 0 0;
  font-weight: 700;
}

.best:empty {
  display: none;
}

/* プレイ */
.play {
  position: relative;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
}

.timer {
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  background: var(--accent);
  transform-origin: left;
}

.play-stats {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 12px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.play-stats strong {
  color: var(--text);
  font-size: 1.1rem;
  font-variant-numeric: tabular-nums;
}

.prompt {
  min-height: 180px;
  margin: 16px 0 8px;
  padding: 24px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-radius: 14px;
  background: #f8fafc;
  transition: background 0.1s;
}

.prompt.miss {
  background: #fee2e2;
}

.prompt p {
  margin: 0;
}

.countdown {
  font-size: 4rem;
  font-weight: 700;
  color: var(--accent);
}

.text {
  font-size: clamp(1.25rem, 5vw, 1.75rem);
  font-weight: 700;
  line-height: 1.4;
}

.kana {
  margin-top: 6px !important;
  font-size: 0.95rem;
  color: var(--muted);
}

.roma {
  margin-top: 14px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(1rem, 4vw, 1.35rem);
  letter-spacing: 0.04em;
  word-break: break-all;
  white-space: pre-wrap;
}

.roma .typed {
  color: var(--accent);
}

.roma .rest {
  color: #94a3b8;
}

.ime-warning {
  margin: 8px 0;
  padding: 8px 12px;
  font-size: 0.85rem;
  color: #92400e;
  background: #fef3c7;
  border-radius: 10px;
}

/* 画面には見せないが、スマホのキーボードを出すために使う入力欄 */
.type-input {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px; /* iOS で拡大されないように */
  border: 0;
  padding: 0;
}

/* 結果 */
#screen-result {
  text-align: center;
}

.result-title {
  margin: 0;
  font-weight: 700;
  color: var(--muted);
}

.score {
  margin: 4px 0 0;
}

.score strong {
  font-size: 3.5rem;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.new-best {
  display: inline-block;
  margin: 4px 0 0;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #92400e;
  background: #fef3c7;
  border-radius: 999px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 20px 0;
}

.result-grid div {
  padding: 10px 4px;
  background: #f8fafc;
  border-radius: 10px;
}

.result-grid dt {
  font-size: 0.75rem;
  color: var(--muted);
}

.result-grid dd {
  margin: 2px 0 0;
  font-weight: 700;
  font-size: 1.1rem;
}

@media (max-width: 480px) {
  .result-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.submit {
  text-align: left;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.submit label {
  font-size: 0.85rem;
}

.submit-row {
  display: flex;
  gap: 8px;
}

.submit-row input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 12px;
  font: inherit;
  font-size: 16px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
}

.submit-message {
  margin: 8px 0 0;
  font-size: 0.85rem;
}

.submit-message:empty {
  display: none;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

/* ランキング */
.ranking-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.seg {
  display: inline-flex;
  padding: 3px;
  background: #f1f5f9;
  border-radius: 10px;
}

.seg.wide {
  display: flex;
  margin-top: 12px;
}

.seg.wide button {
  flex: 1;
}

.seg button {
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
}

.seg button[aria-pressed="true"] {
  color: var(--text);
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}

.rank-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.rank-list li {
  display: grid;
  grid-template-columns: 2.2em 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

.rank-list li.mine {
  background: color-mix(in srgb, var(--accent) 7%, #fff);
}

.rank-list li.empty {
  display: block;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  border: 0;
  padding: 24px 0;
}

.rank {
  font-weight: 700;
  text-align: center;
  color: var(--muted);
}

.rank-list li:nth-child(1) .rank { color: #ca8a04; }
.rank-list li:nth-child(2) .rank { color: #64748b; }
.rank-list li:nth-child(3) .rank { color: #b45309; }

.name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail {
  font-size: 0.75rem;
  color: var(--muted);
}

.pts {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 420px) {
  .detail {
    display: none;
  }
  .rank-list li {
    grid-template-columns: 2.2em 1fr auto;
  }
}
