:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  color: #1d2d26;
  background: #f5f4ed;
  --paper: #fffdf8;
  --ink: #1d2d26;
  --muted: #53675b;
  --line: #dedfd4;
  --green: #18553e;
  --warning: #79451a;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, select, input { font: inherit; }
button, summary { cursor: pointer; }
button { touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible, summary:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid #9e7137;
  outline-offset: 3px;
}
h1, h2, p, figure, dl, dd { margin: 0; }
h1 { font-size: clamp(1.8rem, 6vw, 2.55rem); font-weight: 800; line-height: 1.18; letter-spacing: -.035em; }
h2 { font-size: 1.04rem; font-weight: 750; }

.shell {
  width: min(100%, 38rem);
  margin-inline: auto;
  padding: max(2rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.intro { padding: .25rem .125rem 1.5rem; }
.intro p { margin-top: .7rem; color: var(--muted); line-height: 1.5; }
.example, .hand-panel, .ledger, .conditions {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 1rem;
}
.example { padding: .9rem; margin-bottom: 1rem; }
.example h2 { margin: .15rem .1rem .8rem; }
.example-table {
  position: relative;
  container-type: inline-size;
  width: 100%;
  min-height: 10rem;
  aspect-ratio: 2.15;
  overflow: hidden;
  border-radius: .65rem;
  background: radial-gradient(ellipse at top left, #22644c, #164632 83%);
  border: 1px solid #164632;
  box-shadow: inset 0 0 1.25rem #10392c;
  color: #f2f6ee;
  --sample-width: clamp(.7rem, 5.7cqw, 1.9rem);
  --sample-gap: clamp(1px, .75cqw, 4px);
}
.example-zone { display: grid; justify-items: start; gap: .33rem; }
.example-zone > span { font-size: .75rem; line-height: 1; white-space: nowrap; }
.example-dora { position: absolute; top: 8%; left: 5%; }
.example-win { position: absolute; top: 33%; left: 47%; justify-items: center; }
.example-bottom { position: absolute; inset: auto 5% 10%; display: flex; justify-content: space-between; align-items: end; }
.example-bottom .example-zone:last-child { justify-items: end; }
.example-tiles { display: flex; align-items: end; gap: var(--sample-gap); }
.example-tiles .tile { --tile-width: var(--sample-width); }
.example-tiles .tile-value { font-size: clamp(.61rem, 3.4cqw, 1.13rem); }
.example-tiles .tile-suit { font-size: clamp(.46rem, 2.3cqw, .72rem); }
.example figcaption { margin: .8rem .1rem .1rem; color: var(--muted); font-size: .875rem; line-height: 1.55; }

.primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .7rem;
  width: 100%;
  min-height: 3.35rem;
  border: 1px solid transparent;
  border-radius: .78rem;
  padding: .75rem 1rem;
  color: #fffdf3;
  background: var(--green);
  font-size: 1.08rem;
  font-weight: 750;
}
.primary:disabled { background: #dce2d8; color: #495c51; }
.primary:active:not(:disabled) { background: #12442f; }
.source-link { margin: 1rem .125rem 0; text-align: right; font-size: .75rem; }
.source-link a { color: var(--muted); }
.source-info li { margin-bottom: .45rem; line-height: 1.5; overflow-wrap: anywhere; }
.source-info a { color: var(--green); }
.camera-icon { display: inline-grid; place-items: center; width: 1.25rem; height: .88rem; border: 1.7px solid currentColor; border-radius: .22rem; position: relative; }
.camera-icon::before { content: ''; position: absolute; width: .42rem; height: .16rem; top: -.25rem; left: .18rem; background: currentColor; border-radius: .15rem .15rem 0 0; }
.camera-icon::after { content: ''; width: .42rem; height: .42rem; border: 1.5px solid currentColor; border-radius: 50%; }
.notice { color: var(--muted); font-size: .875rem; line-height: 1.55; }
#modelStatus { margin-top: .68rem; }
.text-button { border: 0; background: transparent; color: var(--green); padding: .6rem .3rem; min-height: 2.6rem; font-weight: 700; }

.result-heading { padding: 0 .125rem .9rem; }
.result-heading h1 { font-size: clamp(1.65rem, 5vw, 2.2rem); }
.score-summary {
  display: grid;
  justify-items: start;
  align-content: center;
  gap: .35rem;
  padding: 1.25rem 1.05rem;
  border-radius: 1rem;
  background: #174835;
  color: #fbf9ec;
  margin-bottom: .85rem;
}
.score-limit { padding: .25rem .54rem; border-radius: .25rem; background: #eddaac; color: #3c2a12; font-size: .85rem; font-weight: 750; }
.score-num { font-size: clamp(2.7rem, 10vw, 4.25rem); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; letter-spacing: -.045em; }
.point-unit { margin-left: .44rem; color: #e1ebdf; }
.score-meta { font-weight: 700; font-variant-numeric: tabular-nums; }
.payment-line { color: #d8e6da; font-size: .875rem; line-height: 1.5; }
.result-message { color: var(--warning); padding: .65rem .8rem; border-radius: .65rem; background: #fff4e2; margin-bottom: .85rem; }
.hand-panel { padding: .9rem; margin-bottom: .85rem; }
.hand-heading { display: flex; justify-content: space-between; align-items: center; gap: .4rem; margin-bottom: .68rem; }
.hand-heading > span, .group-label { color: var(--muted); font-size: .76rem; }
.hand-tiles, .dora-tray { display: flex; flex-wrap: wrap; align-items: end; gap: .52rem .7rem; }
.dora-tray:not(:empty) { border-top: 1px solid var(--line); margin-top: .68rem; padding-top: .6rem; }
.tile-group { display: grid; gap: .2rem; }
.tile-group-faces { display: flex; align-items: end; flex-wrap: wrap; gap: .19rem; }
.tile {
  --tile-width: 1.65rem;
  position: relative;
  display: inline-grid;
  flex: 0 0 auto;
  place-content: center;
  justify-items: center;
  padding: 0;
  width: var(--tile-width);
  height: calc(var(--tile-width) * 1.36);
  border: 1px solid #d0c5ab;
  border-bottom: 3px solid #b5a782;
  border-radius: .22rem;
  background: #fffaf0;
  color: #242c24;
  line-height: 1.02;
}
.tile-sideways { width: calc(var(--tile-width) * 1.36); height: var(--tile-width); }
.tile-sideways .tile-face { transform: rotate(-90deg); }
.tile-face { display: grid; justify-items: center; gap: 1px; }
.tile-value { font-size: .98rem; font-weight: 800; }
.tile-suit { font-size: .62rem; font-weight: 650; }
.suit-m, .suit-z-r, .aka { color: #a72629; }
.suit-p { color: #204c80; }
.suit-s, .suit-z-g { color: #176042; }
.aka.suit-p, .aka.suit-s { color: #a72629; }
.aka { border-top-color: #ce7977; background: #fff4ed; }
.tile-check { border-color: #a26027; box-shadow: inset 0 0 0 1px #a26027; }
.tile-win { outline: 1px solid var(--green); outline-offset: 1px; }
.score-details { display: grid; gap: .85rem; margin-bottom: .85rem; }
.ledger { padding: .9rem 1rem .35rem; }
.ledger h2 { padding-bottom: .35rem; }
.ledger-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .6rem; padding: .56rem 0; border-top: 1px solid var(--line); align-items: baseline; font-size: .94rem; line-height: 1.35; }
.ledger-row dd { color: var(--green); font-weight: 750; font-variant-numeric: tabular-nums; }
.ledger-row:first-child { border-top: 0; }
.ledger-row.total { font-weight: 700; }
.conditions { padding: 0 .9rem; margin-bottom: .85rem; }
.conditions summary { padding: .79rem 0; font-weight: 700; }
.conditions summary > span { margin-left: .65rem; color: var(--muted); font-size: .84rem; font-weight: 500; }
.context-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; padding: .1rem 0 .85rem; }
.context-form label { display: grid; gap: .25rem; font-size: .78rem; color: var(--muted); }
.context-form select { max-width: 100%; min-height: 2.4rem; padding: .25rem .4rem; border-radius: .35rem; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-size: 1rem; }
.context-form .check { display: flex; align-items: end; gap: .35rem; padding-bottom: .55rem; }
.context-form input { inline-size: 1rem; block-size: 1rem; accent-color: var(--green); }

.camera-dialog {
  position: fixed; inset: 0;
  width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; padding: 0; border: 0; background: #101a15; color: #f6faf6;
}
.camera-shell { display: grid; height: 100%; grid-template-rows: minmax(0, 1fr) auto; }
.camera-stage { position: relative; overflow: hidden; background: #101a15; }
#cameraVideo { position: absolute; top: 50%; left: 50%; object-fit: cover; }
.camera-guides { position: absolute; inset: 0; pointer-events: none; }
.guide-box { position: absolute; border: 2px solid; border-radius: .4rem; }
.guide-box span { display: inline-block; margin: .22rem; padding: .16rem .27rem; background: #17251e; color: #fffdf4; border-radius: .2rem; font-size: .73rem; }
.guide-dora { border-color: #f4cc79; }
.guide-hand { border-color: #a6e1bb; }
.camera-control { min-height: 2.5rem; border: 1px solid #749487; color: #fcf9ee; background: #233e32; border-radius: .55rem; padding: .3rem .6rem; font-size: .88rem; }
.camera-close { position: absolute; top: max(.55rem, env(safe-area-inset-top)); right: max(.55rem, env(safe-area-inset-right)); }
.camera-footer { padding: .55rem max(.65rem, env(safe-area-inset-right)) max(.55rem, env(safe-area-inset-bottom)) max(.65rem, env(safe-area-inset-left)); background: #15251d; }
.camera-status { margin: 0 0 .35rem; text-align: center; font-size: .84rem; line-height: 1.38; color: #eef6ee; }
.camera-buttons { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .4rem; min-height: 3.15rem; }
.shutter { grid-column: 2; width: 3.15rem; height: 3.15rem; padding: 0; border-radius: 50%; border: 4px solid #a6e1bb; background: #fffdf4; box-shadow: inset 0 0 0 3px #213e31; }
.shutter:disabled { opacity: .4; }
.rotate-control { grid-column: 3; justify-self: end; white-space: nowrap; }
#btnPhotoFallback { grid-column: 1 / -1; justify-self: center; }
.tile-dialog {
  width: min(calc(100% - 1rem), 31rem); max-height: 82dvh;
  border: 1px solid var(--line); border-radius: 1rem;
  background: var(--paper); color: var(--ink); padding: .8rem;
}
.tile-dialog::backdrop { background: #102017a8; }
.tile-dialog-heading { display: flex; justify-content: space-between; align-items: center; }
.tile-picker { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: .24rem; }
.tile-picker .tile { --tile-width: 100%; height: 2.55rem; }
.tile-review { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem .75rem; margin-bottom: .6rem; }
.tile-review:empty { display: none; }
.tile-review img { inline-size: 2.5rem; block-size: auto; border-radius: .24rem; }
.tile-review > span { color: var(--muted); font-size: .82rem; }

@media (min-width: 34rem) {
  .shell { padding-top: max(3rem, env(safe-area-inset-top)); }
  .example { padding: 1.15rem; }
  .score-details { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}
