/* === Konbini (modern) ================================================
   Card shell around the canvas store + the dialogue panel. Warm paper
   tones, one teal accent and one coral accent, soft shadows, big tap
   targets. Tokens are scoped to .km so the whole thing can drop into the
   site later without fighting its variables.
   ==================================================================== */
.km {
  --bg: #f3ede3; --card: #fffdf9; --panel: #faf6ef; --inset: #f2ece2;
  --ink: #2b2a33; --muted: #736f7e; --faint: #a49fae; --line: #e6dfd3; --line-2: #d9d0c2;
  --accent: #1fa99a; --accent-dark: #15877b; --accent-bg: #e3f5f2; --accent-2: #ff7a59; --sun: #ffcc4d;
  --ok: #3d9a4f; --ok-bg: #e5f4e7; --bad: #d94f4f; --bad-bg: #fbe8e8;
  --shadow: 0 24px 50px -28px rgba(60, 40, 20, .45), 0 2px 6px -2px rgba(60, 40, 20, .12);
  --font-ui: "Nunito", "M PLUS Rounded 1c", system-ui, -apple-system, sans-serif;
  --font-jp: "M PLUS Rounded 1c", "Noto Sans JP", "Hiragino Sans", sans-serif;
}
html.dark .km, .km.km--dark {
  --bg: #1b1a21; --card: #24232b; --panel: #2a2932; --inset: #302f39;
  --ink: #f2eee8; --muted: #aaa5b3; --faint: #7d7887; --line: #3a3944; --line-2: #4a4856;
  --accent: #33c2b1; --accent-dark: #22a595; --accent-bg: #1f3a37; --accent-2: #ff8d70;
  --ok: #5bb86b; --ok-bg: #1f3324; --bad: #ee6b6b; --bad-bg: #3b2222;
  --shadow: 0 24px 50px -28px rgba(0, 0, 0, .8);
}
@media (prefers-color-scheme: dark) {
  html:not(.light) .km:not(.km--light) {
    --bg: #1b1a21; --card: #24232b; --panel: #2a2932; --inset: #302f39;
    --ink: #f2eee8; --muted: #aaa5b3; --faint: #7d7887; --line: #3a3944; --line-2: #4a4856;
    --accent: #33c2b1; --accent-dark: #22a595; --accent-bg: #1f3a37; --accent-2: #ff8d70;
    --ok: #5bb86b; --ok-bg: #1f3324; --bad: #ee6b6b; --bad-bg: #3b2222;
    --shadow: 0 24px 50px -28px rgba(0, 0, 0, .8);
  }
}

.km {
  position: relative; box-sizing: border-box;
  width: min(980px, 100%); margin: 0 auto;
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 18px 20px; border-radius: 26px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
  font-family: var(--font-ui); color: var(--ink);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
}
.km *, .km *::before, .km *::after { box-sizing: border-box; }
.km button { font-family: inherit; color: inherit; }
.km *:focus { outline: none; }
.km *:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.km [hidden] { display: none !important; }

/* ── header ── */
.km__top { display: flex; align-items: center; gap: 14px; }
.km__daybadge {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 54px; height: 54px; border-radius: 18px; color: #fff;
  background: linear-gradient(160deg, var(--accent), var(--accent-dark)); box-shadow: 0 10px 22px -10px var(--accent);
}
.km__daybadge small { font-size: 9px; font-weight: 800; letter-spacing: .14em; opacity: .85; line-height: 1; }
.km__daybadge b { font-size: 24px; font-weight: 800; line-height: 1; margin-top: 3px; }
.km__title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.km__name { font-weight: 800; font-size: 21px; letter-spacing: -.01em; line-height: 1.1; white-space: nowrap; }
.km__name-kana { font-family: var(--font-jp); font-weight: 700; font-size: 14px; color: var(--accent); margin-left: 6px; vertical-align: 2px; }
.km__sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.km__stats { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.km__stat { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 12px; background: var(--inset); border: 1px solid var(--line); font-size: 13px; font-weight: 800; color: var(--ink); white-space: nowrap; }
.km__stat--yen { color: var(--accent-dark); font-variant-numeric: tabular-nums; }
.km__cust { display: inline-flex; gap: 3px; align-items: center; }
.km__stat--cust:has(.km__cust:empty) { display: none; }
.km__cust i { width: 7px; height: 7px; border-radius: 50%; background: var(--line-2); transition: background .25s, transform .25s; }
.km__cust i.is-done { background: var(--accent); }
.km__cust i.is-now { background: var(--accent-2); transform: scale(1.25); }
.km__actions { display: flex; align-items: center; gap: 8px; }
.km__iconbtn {
  cursor: pointer; width: 38px; height: 38px; border-radius: 12px; padding: 0;
  border: 1px solid var(--line); background: var(--inset); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; transition: background .2s, color .2s, transform .15s;
}
.km__iconbtn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.km__iconbtn:hover { background: var(--accent-bg); color: var(--accent-dark); }
.km__iconbtn:active { transform: scale(.94); }
.km__iconbtn.is-on { background: var(--accent-bg); color: var(--accent-dark); border-color: var(--accent); }

/* ── stage (canvas + overlays) ── */
.km__stage { position: relative; display: flex; justify-content: center; align-items: center; border-radius: 20px; overflow: hidden; background: #ede5d8; border: 1px solid var(--line); }
.km__canvas { display: block; cursor: pointer; touch-action: none; max-width: 100%; transform: translateZ(0); }
.km__stage.is-shake .km__canvas { animation: km-shake .28s; }
@keyframes km-shake { 0%, 100% { transform: translate(0, 0); } 20% { transform: translate(-4px, 2px); } 40% { transform: translate(4px, -2px); } 60% { transform: translate(-3px, 1px); } 80% { transform: translate(3px, -1px); } }

.km__banner {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  padding: 14px 34px; border-radius: 999px; background: rgba(43, 42, 51, .92); color: #fff; text-align: center;
  animation: km-banner 2.4s ease both; pointer-events: none;
}
.km__banner b { display: block; font-size: 24px; font-weight: 800; letter-spacing: -.01em; }
.km__banner span { display: block; font-size: 13px; opacity: .85; margin-top: 2px; }
@keyframes km-banner { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.9); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -60%) scale(.98); } }
.km__toast {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 999px; background: #fff; color: var(--ink); font-weight: 700; font-size: 13px; box-shadow: 0 10px 24px -12px rgba(0, 0, 0, .4);
  animation: km-toast .25s ease both; pointer-events: none; white-space: nowrap; font-family: var(--font-jp);
}
html.dark .km__toast { background: #3a3944; color: #f2eee8; }
@keyframes km-toast { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.km__overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(35, 30, 40, .42); }
.km__overlay--title { align-items: flex-end; background: linear-gradient(to bottom, rgba(35, 30, 40, 0) 30%, rgba(35, 30, 40, .35)); }
.km__ovcard {
  width: min(420px, 100%); padding: 26px 26px 22px; border-radius: 24px; background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .5); text-align: center; animation: km-pop .35s cubic-bezier(.2, .9, .3, 1.2) both;
}
@keyframes km-pop { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
.km__logo { font-size: 44px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.km__logo-kana { display: block; font-family: var(--font-jp); font-weight: 800; font-size: 20px; color: var(--accent); margin-top: 6px; letter-spacing: .3em; }
.km__tag { color: var(--muted); font-size: 14px; margin: 12px 0 18px; line-height: 1.45; }
.km__btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 50px; padding: 0 20px; margin-top: 8px;
  border-radius: 16px; border: 1px solid var(--line-2); background: var(--inset); font-size: 16px; font-weight: 800; cursor: pointer;
  transition: transform .12s, background .2s, box-shadow .2s;
}
.km__btn:hover { background: var(--accent-bg); }
.km__btn:active { transform: scale(.97); }
.km__btn--primary { background: linear-gradient(160deg, var(--accent), var(--accent-dark)); color: #fff; border-color: transparent; box-shadow: 0 14px 28px -14px var(--accent); }
.km__btn--primary:hover { background: linear-gradient(160deg, var(--accent), var(--accent-dark)); filter: brightness(1.05); }
.km__btn--danger { color: var(--bad); }
.km__btn small { font-weight: 600; opacity: .8; }
.km__stars { font-size: 34px; letter-spacing: .12em; color: var(--sun); margin: 6px 0 2px; text-shadow: 0 2px 0 rgba(0, 0, 0, .08); }
.km__stars i { font-style: normal; display: inline-block; animation: km-star .5s cubic-bezier(.2, .9, .3, 1.3) both; }
.km__stars i.is-off { color: var(--line-2); }
.km__stars i:nth-child(2) { animation-delay: .15s; } .km__stars i:nth-child(3) { animation-delay: .3s; }
@keyframes km-star { from { transform: scale(0) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
.km__ovcard--fired .km__sum-jp { color: var(--bad); }
.km__sum-fired { font-size: 13.5px; color: var(--muted); margin: 4px 0 8px; line-height: 1.45; }
.km__sum-yen { font-size: 34px; font-weight: 800; color: var(--accent-dark); font-variant-numeric: tabular-nums; }
.km__sum-row { display: flex; justify-content: center; gap: 18px; color: var(--muted); font-size: 13px; margin: 6px 0; }
.km__sum-row b { color: var(--ink); }
.km__sum-new { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 12px 0 6px; }
.km__sum-new .km__pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border-radius: 999px; background: var(--inset); border: 1px solid var(--line); font-size: 12px; font-family: var(--font-jp); font-weight: 700; }
.km__sum-new canvas { width: 26px; height: 26px; }
.km__sum-jp { font-family: var(--font-jp); font-weight: 700; font-size: 17px; color: var(--muted); }

/* ── dialogue panel ── */
.km__panel { position: relative; display: flex; flex-direction: column; gap: 12px; min-height: 196px; padding: 16px 18px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); cursor: default; }
.km__panel.is-tappable { cursor: pointer; }
.km__ctx { display: flex; flex-direction: column; gap: 4px; animation: km-line .22s ease both; }
.km__ctx.is-instruction .km__jp { font-family: var(--font-ui); font-size: 16px; font-weight: 700; color: var(--ink); }
@keyframes km-line { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.km__speaker { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.km__avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--inset); border: 2px solid var(--line-2); }
.km__speaker.is-you .km__avatar { border-color: var(--accent); }
.km__speaker-name { font-family: var(--font-jp); font-weight: 800; font-size: 14px; }
.km__speaker-en { font-size: 12px; color: var(--muted); }
.km__line { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.km__jp { font-family: var(--font-jp); font-weight: 700; font-size: 24px; line-height: 1.3; letter-spacing: .01em; }
.km__ro { font-size: 14px; color: var(--muted); font-style: italic; }
.km__en { font-size: 14.5px; color: var(--ink); opacity: .9; line-height: 1.4; }
.km__ctx.is-instruction .km__en { color: var(--muted); }
.km--no-ro .km__ro, .km--no-ro .km__choice-detail i { display: none; }
.km--no-en .km__en, .km--no-en .km__choice-detail b { display: none; }
.is-learned .km__ro, .is-learned .km__en, .km__choice.is-learned .km__choice-detail { display: none; }

.km__badge { display: inline-block; flex: none; font-size: 10px; font-weight: 800; letter-spacing: .08em; line-height: 1; padding: 4px 6px; border-radius: 6px; background: var(--line-2); color: #fff; vertical-align: middle; }
.is-new > .km__line > .km__badge, .km__choice.is-new .km__badge { background: #2f6fd6; }
.is-learning > .km__line > .km__badge, .km__choice.is-learning .km__badge { background: #d68a2f; }
.is-learned > .km__line > .km__badge, .km__choice.is-learned .km__badge { background: var(--ok); }

.km__choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 420px) { .km__choices { grid-template-columns: 1fr; } }
.km__choices:empty { display: none; }
.km__choice {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-height: 54px; padding: 11px 14px 11px 16px; text-align: left;
  border-radius: 16px; border: 1.5px solid var(--line-2); background: var(--card); cursor: pointer;
  transition: border-color .15s, background .15s, transform .12s, box-shadow .2s; animation: km-line .25s ease both;
}
.km__choice:nth-child(2) { animation-delay: .04s; } .km__choice:nth-child(3) { animation-delay: .08s; } .km__choice:nth-child(4) { animation-delay: .12s; }
.km__choice:hover { border-color: var(--accent); }
.km__choice:active { transform: scale(.985); }
.km__choice .km__badge { position: absolute; top: 10px; right: 10px; }
.km__choice-jp { font-family: var(--font-jp); font-weight: 700; font-size: 19px; line-height: 1.3; padding-right: 40px; }
.km__choice-detail { display: none; flex-direction: column; gap: 1px; font-size: 13px; }
.km__choice-detail i { color: var(--muted); }
.km__choice-detail b { font-weight: 700; }
.km__choice-hint { display: none; position: absolute; right: 12px; bottom: 9px; font-size: 11px; color: var(--accent-dark); font-weight: 700; }
.km__choice.is-sel { border-color: var(--accent); background: var(--accent-bg); box-shadow: 0 0 0 3px var(--accent-bg); }
.km__choice.is-sel .km__choice-detail { display: flex; }
.km__choice.is-sel::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 4px 4px 0; background: var(--accent); }
@media (pointer: coarse) { .km__choice.is-sel .km__choice-hint { display: block; } }
.km__choice.is-ok { border-color: var(--ok); background: var(--ok-bg); }
.km__choice.is-ok::before { background: var(--ok); }
.km__choice.is-wrong { border-color: var(--bad); background: var(--bad-bg); animation: km-shake .3s; }
.km__choice.is-wrong::before { background: var(--bad); }
.km__choice.is-dead { opacity: .45; pointer-events: none; text-decoration: line-through; text-decoration-color: var(--bad); }

.km__cta { margin-top: auto; align-self: flex-end; font-size: 12px; font-weight: 700; color: var(--faint); animation: km-cta 1.4s ease-in-out infinite; }
@keyframes km-cta { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }
.km__hint { font-size: 12px; color: var(--faint); }

/* ── modals (Words / Settings) ── */
.km__modal { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(35, 30, 40, .5); border-radius: 26px; }
.km__modal-card { width: min(560px, 100%); max-height: min(78vh, 640px); display: flex; flex-direction: column; border-radius: 22px; background: var(--card); border: 1px solid var(--line); box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .55); overflow: hidden; animation: km-pop .3s cubic-bezier(.2, .9, .3, 1.2) both; }
.km__modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 12px; border-bottom: 1px solid var(--line); }
.km__modal-head h3 { margin: 0; font-size: 18px; font-weight: 800; }
.km__modal-body { overflow: auto; padding: 8px 18px 18px; -webkit-overflow-scrolling: touch; }
.km__modal-close { cursor: pointer; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--inset); color: var(--muted); font-size: 18px; line-height: 1; }
.km__section { margin-top: 14px; }
.km__section h4 { margin: 0 0 8px; font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); }
.km__wordrow { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 12px; cursor: pointer; }
.km__wordrow:hover { background: var(--inset); }
.km__wordrow canvas { width: 34px; height: 34px; flex: none; }
.km__wordrow .jp { font-family: var(--font-jp); font-weight: 700; font-size: 17px; }
.km__wordrow .ro { font-size: 12px; color: var(--muted); font-style: italic; }
.km__wordrow .en { margin-left: auto; text-align: right; font-size: 13px; color: var(--muted); }
.km__wordrow .glyph { width: 20px; height: 20px; flex: none; }
.km__itemgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.km__itemcard { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border-radius: 14px; background: var(--inset); border: 1px solid var(--line); text-align: center; cursor: pointer; }
.km__itemcard canvas { width: 40px; height: 40px; }
.km__itemcard .jp { font-family: var(--font-jp); font-weight: 700; font-size: 13px; line-height: 1.2; }
.km__itemcard .en { font-size: 11px; color: var(--muted); }
.km__table { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 14px; }
.km__table div { display: flex; gap: 10px; align-items: center; padding: 5px 8px; border-radius: 8px; }
.km__table div:hover { background: var(--inset); }
.km__table span:first-child { min-width: 46px; font-size: 12px; color: var(--muted); font-weight: 700; line-height: 1.2; }
.km__table span.jp { white-space: nowrap; }
.km__table span.jp { font-family: var(--font-jp); font-weight: 700; font-size: 15px; }
.km__person { display: flex; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); }
.km__person:last-child { border-bottom: 0; }
.km__person canvas { width: 44px; height: 44px; flex: none; border-radius: 50%; background: var(--inset); border: 2px solid var(--line-2); }
.km__person-name .jp { font-family: var(--font-jp); font-weight: 800; font-size: 16px; }
.km__person-name .en { font-size: 12px; color: var(--muted); margin-left: 4px; }
.km__person ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; color: var(--ink); line-height: 1.45; }
.km__person li { margin: 2px 0; }
.km__toast { max-width: 90%; white-space: normal; text-align: center; }
.km__setrow { display: flex; align-items: center; gap: 12px; padding: 12px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.km__setrow:last-child { border-bottom: 0; }
.km__setrow b { font-size: 15px; }
.km__setrow small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.km__switch { margin-left: auto; flex: none; width: 46px; height: 26px; border-radius: 13px; background: var(--line-2); position: relative; transition: background .2s; }
.km__switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .25); transition: transform .2s; }
.km__switch.is-on { background: var(--accent); }
.km__switch.is-on::after { transform: translateX(20px); }

/* ── wide desktop: canvas left, dialogue right ── */
.km--wide { display: grid; grid-template-columns: 1fr 360px; grid-template-areas: "top top" "stage panel"; align-items: start; }
.km--wide .km__top { grid-area: top; }
.km--wide .km__stage { grid-area: stage; }
.km--wide .km__panel { grid-area: panel; align-self: stretch; min-height: 0; }
.km--wide .km__choices { grid-template-columns: 1fr; }

/* ── phone fullscreen (JS adds km--fs) ── */
.km--fs { position: fixed; inset: 0; z-index: 1000; width: 100%; max-width: none; margin: 0; border-radius: 0; border: 0; gap: 8px; padding: max(6px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom)); overflow: hidden; }
.km--fs .km__top { padding: 0 10px; gap: 10px; }
.km--fs .km__daybadge { width: 42px; height: 42px; border-radius: 13px; }
.km--fs .km__daybadge b { font-size: 18px; }
.km--fs .km__name { font-size: 17px; }
.km--fs .km__name-kana { display: none; }
.km--fs .km__sub { font-size: 11.5px; }
.km--fs .km__stat { height: 30px; padding: 0 9px; font-size: 12px; }
.km--fs .km__iconbtn { width: 34px; height: 34px; }
.km--fs .km__stage { flex: none; border-radius: 0; border-left: 0; border-right: 0; }
.km--fs .km__panel { flex: 1 1 auto; margin: 0 8px; overflow: auto; min-height: 0; }
.km--fs .km__jp { font-size: 22px; }
.km--fs .km__choices { grid-template-columns: 1fr 1fr; gap: 8px; }
.km--fs .km__choice { min-height: 48px; padding: 9px 10px 9px 13px; }
.km--fs .km__choice-jp { font-size: 16px; padding-right: 0; }
.km--fs .km__choice .km__badge { position: static; order: -1; font-size: 8px; padding: 3px 5px; margin-bottom: 1px; }
.km--fs .km__choice-hint { position: static; margin-top: 2px; }
.km--fs .km__modal { border-radius: 0; }
@media (max-width: 560px) {
  .km { padding: 12px 12px 14px; border-radius: 20px; gap: 10px; }
  .km__name-kana, .km__sub { display: none; }
  .km__stat--cust { display: none; }
  .km__jp { font-size: 21px; }
  .km__choices { grid-template-columns: 1fr 1fr; gap: 8px; }
  .km__choice { padding: 9px 10px 9px 13px; min-height: 48px; }
  .km__choice-jp { font-size: 16px; padding-right: 0; }
  .km__choice .km__badge { position: static; order: -1; font-size: 8px; padding: 3px 5px; margin-bottom: 1px; }
  .km__choice-hint { position: static; margin-top: 2px; }
  .km__panel { padding: 12px 12px; min-height: 170px; }
}
