:root {
  --ink: #19231d;
  --muted: #65736a;
  --paper: #f4f1e8;
  --panel: #fffdf7;
  --line: #d8d4c7;
  --green: #155b3b;
  --green-dark: #0b3b26;
  --green-soft: #e2eee6;
  --gold: #c9953d;
  --red: #b33a32;
  --shadow: 0 16px 45px rgb(35 49 40 / 9%);
  font-family: Inter, "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 85% 0%, rgb(201 149 61 / 14%), transparent 28rem),
    var(--paper);
}

button, input, select { font: inherit; }
button { color: inherit; }

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 2rem;
  max-width: 1180px;
  margin: 0 auto;
  padding: 4.5rem 2rem 2.5rem;
}

.eyebrow, .step {
  margin: 0 0 .6rem;
  color: var(--green);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: clamp(2.6rem, 6vw, 5rem); line-height: .95; }
.lead { margin: 1rem 0 0; color: var(--muted); }

.runtime {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .7rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgb(255 253 247 / 75%);
  color: var(--muted);
  font-size: .82rem;
  white-space: nowrap;
}

.status-dot { width: .55rem; height: .55rem; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 4px rgb(201 149 61 / 15%); }
.status-dot.ready { background: #2b9660; box-shadow: 0 0 0 4px rgb(43 150 96 / 15%); }
.status-dot.error { background: var(--red); box-shadow: 0 0 0 4px rgb(179 58 50 / 15%); }

main { max-width: 1180px; margin: 0 auto; padding: 0 2rem 5rem; }

.panel {
  margin-bottom: 1.25rem;
  padding: 2rem;
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.7rem; }
h2 { margin: 0; font-family: Georgia, "Yu Mincho", serif; font-size: 1.65rem; }
h3 { margin: 0; font-size: .85rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; }

.button {
  border: 1px solid transparent;
  border-radius: .65rem;
  padding: .65rem .9rem;
  background: var(--green);
  color: white;
  cursor: pointer;
  font-weight: 700;
  font-size: .82rem;
}
.button.secondary { color: var(--green); border-color: var(--green); background: white; }
.button.ghost { color: var(--muted); border-color: var(--line); background: transparent; }
.button.small { padding: .45rem .7rem; }
.button:hover { transform: translateY(-1px); }

.zones { display: grid; grid-template-columns: minmax(0, 1fr) 130px; gap: 1rem; }
.secondary-zones { grid-template-columns: 1.4fr 1fr 1fr; margin-top: 1rem; }
.zone { min-width: 0; padding: 1rem; border: 1px solid var(--line); border-radius: .8rem; background: #faf8f1; }
.target-zone { position: relative; cursor: pointer; transition: border-color .15s ease, box-shadow .15s ease, background-color .15s ease; }
.target-zone:hover { border-color: #8caa98; }
.target-zone:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.target-zone.active-target { border-color: var(--green); background: #f5faf6; box-shadow: inset 0 0 0 1px var(--green); }
.zone-label { display: flex; justify-content: space-between; align-items: center; min-height: 1.25rem; margin-bottom: .7rem; }
.zone-label span { color: var(--muted); font-size: .72rem; }
.tile-row, .meld-row { display: flex; gap: .16rem; min-height: 3.7rem; align-items: flex-end; flex-wrap: wrap; }
.tile-row.empty::after, .meld-row.empty::after { content: "未選択"; align-self: center; color: #a09d94; font-size: .78rem; }

.tile {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 2.5rem;
  height: 3.5rem;
  padding: 0;
  border: 0;
  border-radius: .32rem;
  background: linear-gradient(145deg, #fff, #f1eee4);
  box-shadow: none;
  cursor: pointer;
  font-family: Georgia, serif;
  font-size: 1.05rem;
  font-weight: 700;
}
.tile:hover { transform: translateY(-3px); filter: drop-shadow(0 5px 4px rgb(21 49 34 / 18%)); }
.tile:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.tile img { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.tile .tile-front { z-index: 1; }
.tile .tile-face { z-index: 2; }
.tile-fallback { position: relative; z-index: 0; }
.tile-image-loaded .tile-fallback, .tile-image-loaded .suit-mark { visibility: hidden; }
.tile.sou { color: #177343; }
.tile.pin { color: #245d91; }
.tile.honor { color: #27362d; }
.tile.green-dragon { color: #177343; }
.tile.red-dragon { color: var(--red); }
.tile.red-five { color: var(--red); }
.tile .suit-mark { position: absolute; right: .2rem; bottom: .05rem; z-index: 0; color: currentColor; font-size: .55rem; font-family: sans-serif; font-weight: 700; }

.meld { display: flex; gap: .12rem; padding: .3rem; border: 1px solid var(--line); border-radius: .45rem; background: white; }
.meld::before { content: attr(data-label); align-self: center; margin: 0 .2rem; color: var(--muted); font-size: .65rem; writing-mode: vertical-rl; }
.meld .tile { width: 2rem; height: 2.8rem; font-size: .88rem; }

.picker { margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.meld-builder { display: flex; align-items: center; gap: .8rem; margin: -.15rem 0 1rem; padding: .75rem; border-radius: .7rem; background: var(--green-soft); }
.meld-builder label { display: flex; align-items: center; gap: .5rem; font-size: .78rem; font-weight: 700; }
.meld-draft { flex: 1; color: var(--green-dark); font-size: .8rem; }

.tile-palette { display: grid; grid-template-columns: repeat(10, 2.5rem); gap: .26rem; align-items: center; }
.palette-break { grid-column: 1 / -1; height: .15rem; }
.picker-help { margin: .8rem 0 0; color: var(--muted); font-size: .72rem; }

.form-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: .8rem; }
.form-grid label { display: flex; flex-direction: column; gap: .4rem; color: var(--muted); font-size: .72rem; font-weight: 700; }
select, input[type="number"] { width: 100%; min-height: 2.7rem; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: .55rem; background: white; color: var(--ink); }
.checks { display: flex; gap: .65rem 1.2rem; flex-wrap: wrap; margin-top: 1.2rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.checks label { font-size: .82rem; cursor: pointer; }
.checks input { accent-color: var(--green); }

.calculate-section { display: flex; flex-direction: column; align-items: center; gap: .65rem; padding: 1.5rem 0 2.5rem; }
.calculate-button { min-width: min(100%, 22rem); padding: 1rem 2rem; border: 0; border-radius: .8rem; background: var(--green); color: white; box-shadow: 0 10px 24px rgb(21 91 59 / 22%); cursor: pointer; font-size: 1rem; font-weight: 800; }
.calculate-button:disabled { background: #a9afa9; box-shadow: none; cursor: not-allowed; }
.calculate-section p { margin: 0; color: var(--muted); font-size: .75rem; }

.result-panel { min-height: 13rem; }
.result-placeholder { text-align: center; padding: 1rem; color: var(--muted); }
.result-placeholder h2 { color: var(--ink); }
.result-placeholder p:last-child { font-size: .85rem; }
.result-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--line); }
.score-main { display: flex; align-items: baseline; gap: .45rem; }
.score-main strong { font-family: Georgia, serif; font-size: clamp(2.5rem, 6vw, 4.3rem); color: var(--green-dark); }
.score-main span { font-weight: 700; }
.payment-main { text-align: right; }
.payment-main strong { display: block; font-size: 1.5rem; }
.payment-main span { color: var(--muted); font-size: .72rem; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; padding-top: 1.5rem; }
.result-list { display: grid; gap: .45rem; margin: .7rem 0 0; }
.result-item { display: flex; justify-content: space-between; padding: .55rem .7rem; border-radius: .45rem; background: #f5f3ec; font-size: .82rem; }
.result-error { padding: 1rem; border-left: 4px solid var(--red); background: #fff3f1; }
.result-error h2 { color: var(--red); }
.result-error code { color: var(--muted); }

.debug-panel { margin-top: 1rem; border: 1px solid var(--line); border-radius: .8rem; background: rgb(255 253 247 / 65%); }
.debug-panel summary { padding: 1rem 1.2rem; cursor: pointer; color: var(--muted); font-size: .8rem; font-weight: 700; }
.debug-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 0 1.2rem 1.2rem; }
pre { max-height: 24rem; overflow: auto; padding: 1rem; border-radius: .5rem; background: #1d2821; color: #dceade; font-size: .68rem; white-space: pre-wrap; word-break: break-word; }

footer { display: flex; justify-content: space-between; gap: 1rem; max-width: 1180px; margin: 0 auto; padding: 1.5rem 2rem 3rem; color: var(--muted); font-size: .75rem; }
footer a { color: var(--green); }
.footer-links { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.hidden { display: none !important; }

@media (max-width: 860px) {
  .hero { align-items: flex-start; flex-direction: column; padding-top: 3rem; }
  .secondary-zones, .form-grid { grid-template-columns: repeat(2, 1fr); }
  .tile-palette { grid-template-columns: repeat(9, 2.5rem); }
}

@media (max-width: 600px) {
  .hero, main, footer { padding-left: 1rem; padding-right: 1rem; }
  .panel { padding: 1.2rem; border-radius: .8rem; }
  .zones, .secondary-zones, .form-grid, .result-grid, .debug-grid { grid-template-columns: 1fr; }
  .compact-zone { max-width: 8rem; }
  .section-heading { flex-direction: column; }
  .tile-palette { grid-template-columns: repeat(8, 2.25rem); }
  .tile { width: 2.25rem; height: 3.15rem; }
  .result-heading { flex-direction: column; }
  .payment-main { text-align: left; }
  footer { flex-direction: column; }
  .footer-links { justify-content: flex-start; }
}

@media (max-width: 380px) {
  .tile-palette { grid-template-columns: repeat(6, 2.25rem); }
}
