:root {
  color-scheme: light;
  --paper: #f5efe2;
  --ink: #1d2421;
  --muted: #6d7871;
  --green: #195f4b;
  --deep-green: #083b2b;
  --red: #b64035;
  --gold: #d8b15a;
  --blue: #245d78;
  --tile: #fffdf7;
  --line: rgba(30, 35, 40, 0.14);
  --shadow: 0 16px 40px rgba(8, 28, 22, 0.22);
  --panel: rgba(255, 253, 247, 0.94);
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  background:
    linear-gradient(180deg, rgba(9, 47, 36, 0.2), rgba(9, 47, 36, 0.54)),
    url("./assets/mat.png") center / cover fixed,
    #083b2b;
  color: var(--ink);
  font-family: "Yu Gothic", "Hiragino Sans", system-ui, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(79, 48, 23, 0.2), transparent 14%, transparent 86%, rgba(79, 48, 23, 0.2)),
    radial-gradient(circle at 50% -8%, rgba(255, 245, 209, 0.25), transparent 24rem);
}

button {
  color: inherit;
  font: inherit;
}

.app-shell {
  position: relative;
  width: min(100%, 780px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 10px 9px 18px;
  display: grid;
  gap: 8px;
}

.top-bar,
.teacher-head,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.kicker,
.goal-label,
.drawn-tile-wrap p {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.08rem, 4.6vw, 1.7rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.top-bar {
  color: #fffdf7;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.32);
}

.top-tag {
  margin-left: auto;
  padding: 5px 9px;
  border: 1px solid rgba(255, 253, 247, 0.2);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.13);
  color: rgba(255, 253, 247, 0.92);
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.top-bar .kicker {
  color: rgba(255, 253, 247, 0.72);
}

h2 {
  margin-bottom: 0;
  font-size: 1.18rem;
  letter-spacing: 0;
}

.icon-button {
  width: auto;
  height: 38px;
  min-width: 94px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.72);
  box-shadow: 0 8px 22px rgba(31, 38, 44, 0.1);
  font-size: 0.82rem;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
}

.icon-button span:first-child {
  font-size: 1rem;
  line-height: 1;
}

.goal-band {
  padding: 6px 8px;
  border: 1px solid rgba(216, 177, 90, 0.46);
  border-left: 5px solid var(--gold);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.made-groups {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.72);
}

.goal-text {
  margin-bottom: 0;
  font-size: clamp(0.88rem, 3.5vw, 1.12rem);
  font-weight: 900;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.progress-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-top: 4px;
}

.progress-strip span {
  min-height: 21px;
  padding: 3px 5px;
  border-radius: 6px;
  background: #edf3ef;
  color: var(--green);
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 0.74rem;
  font-weight: 900;
}

.goal-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.5;
  font-size: 0.76rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.play-area {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 5px;
  align-items: end;
  padding: 8px 7px 9px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 253, 247, 0.06), rgba(255, 253, 247, 0.02)),
    rgba(4, 43, 31, 0.24);
  border: 1px solid rgba(255, 253, 247, 0.12);
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.14);
}

.drawn-tile-wrap {
  display: grid;
  grid-column: 1 / span 2;
  grid-row: 1;
  justify-items: center;
  gap: 4px;
}

.hand {
  display: grid;
  grid-column: 3 / span 6;
  grid-row: 1 / span 2;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
  align-items: end;
}

.hand .tile:nth-child(n + 7) {
  transform: translateX(calc(-100% - 5px));
}

.tile {
  position: relative;
  width: 100%;
  aspect-ratio: 0.66;
  min-height: 60px;
  border: 1px solid rgba(26, 31, 28, 0.24);
  border-radius: 6px;
  background:
    url("./assets/tile-base.png") center / 132% 116% no-repeat,
    linear-gradient(180deg, #fffef9 0%, #fdf9ee 54%, #eadfc7 100%);
  box-shadow: 5px 7px 13px rgba(3, 20, 15, 0.38);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
  overflow: hidden;
}

.tile:focus-visible,
.tile.recommended {
  outline: 3px solid rgba(216, 177, 90, 0.72);
  outline-offset: 2px;
}

.tile.made {
  border-color: rgba(36, 92, 75, 0.76);
  background: linear-gradient(180deg, #fffefb 0%, #eaf4ed 100%);
}

.tile.made::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(36, 92, 75, 0.38);
  border-radius: 4px;
  pointer-events: none;
}

.tile::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(22, 85, 68, 0.34);
  border-radius: 4px;
  pointer-events: none;
}

.tile::after {
  content: none;
}

.tile.group-1 {
  border-color: rgba(45, 93, 123, 0.78);
  background: linear-gradient(180deg, #fffefb 0%, #e9f1f6 100%);
}

.tile.group-2 {
  border-color: rgba(184, 70, 58, 0.7);
  background: linear-gradient(180deg, #fffefb 0%, #f8ece8 100%);
}

.tile.group-3 {
  border-color: rgba(217, 164, 65, 0.82);
  background: linear-gradient(180deg, #fffefb 0%, #fbf2d7 100%);
}

.tile:active {
  transform: translate(3px, 4px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.9),
    inset 0 -7px 9px rgba(107, 85, 54, 0.18),
    1px 2px 0 #d0c0a2,
    3px 5px 10px rgba(3, 20, 15, 0.3);
}

.tile-symbol {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 0;
  place-items: center;
  font-weight: 900;
  line-height: 1;
  width: 100%;
  height: 100%;
  padding: 6px 4px 5px;
  position: relative;
  z-index: 1;
}

.tile-number {
  font-family: Georgia, "Times New Roman", "Yu Mincho", serif;
  font-size: clamp(1.34rem, 7.8vw, 2.22rem);
  font-weight: 900;
  line-height: 0.88;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.76);
}

.tile-suit {
  font-size: 0.56rem;
  color: var(--muted);
  font-weight: 900;
}

.tile-face {
  display: grid;
  place-items: center;
  min-height: 16px;
  width: 100%;
  font-weight: 900;
}

.pin-dots {
  display: grid;
  place-items: center;
}

.pin-dot {
  width: 15px;
  height: 15px;
  border-radius: 999px;
  border: 2px solid currentColor;
  background:
    radial-gradient(circle, transparent 0 28%, currentColor 30% 42%, transparent 44%),
    radial-gradient(circle, currentColor 0 12%, transparent 14%);
}

.bamboo-mark {
  display: flex;
  gap: 2px;
  justify-content: center;
  align-items: center;
}

.bamboo-mark span {
  width: 8px;
  height: 22px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: inset 0 7px 0 rgba(255, 255, 255, 0.28), inset 0 14px 0 rgba(0, 0, 0, 0.1);
}

.man-mark,
.dragon-mark {
  font-family: "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-size: 0.94rem;
  line-height: 1;
}

.dragon-tile .tile-symbol {
  grid-template-rows: 1fr auto;
}

.dragon-tile .tile-number {
  align-self: center;
  justify-self: center;
  font-size: clamp(1.72rem, 9.5vw, 2.6rem);
  line-height: 1;
  width: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  transform: translateX(-0.12em);
}

.dragon-tile .tile-face {
  display: none;
}

.man .tile-number,
.dragon-red .tile-number {
  color: var(--red);
}

.pin .tile-number {
  color: var(--blue);
}

.sou .tile-number,
.dragon-green .tile-number {
  color: var(--green);
}

.drawn {
  width: 46px;
  min-height: 62px;
  outline: 3px solid rgba(216, 177, 90, 0.62);
  outline-offset: 2px;
}

.win-panel {
  padding: 12px 13px;
  border: 2px solid rgba(216, 177, 90, 0.75);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(216, 177, 90, 0.2), rgba(255, 253, 247, 0.96) 35%),
    #fffdf7;
  box-shadow: 0 18px 46px rgba(3, 20, 15, 0.34);
}

.win-panel h2 {
  margin: 0 0 5px;
  font-size: 1.28rem;
}

.win-panel p:not(.kicker) {
  color: #39413d;
  font-size: 0.92rem;
  line-height: 1.45;
}

.made-groups {
  display: grid;
  gap: 10px;
}

.made-summary {
  margin-bottom: 0;
  font-size: 1.05rem;
  font-weight: 900;
}

.group-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.group-chip {
  padding: 8px 10px;
  border-radius: 8px;
  background: #edf3ef;
  color: var(--green);
  font-weight: 900;
  line-height: 1.2;
}

.group-chip.group-1 {
  background: #e9f1f6;
  color: var(--blue);
}

.group-chip.group-2 {
  background: #f8ece8;
  color: var(--red);
}

.group-chip.group-3 {
  background: #fbf2d7;
  color: #83610d;
}

.teacher-panel {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.badge {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 999px;
  background: #e8f0ea;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
}

.teacher-reason {
  margin: 8px 0;
  color: #39413d;
  font-size: 0.86rem;
  line-height: 1.45;
}

.teacher-reason ul {
  margin: 0;
  padding-left: 1.25em;
}

.teacher-reason li + li {
  margin-top: 3px;
}

.remaining-panel,
.wall-panel {
  margin: 8px 0 9px;
  padding: 8px 9px;
  border-radius: 7px;
  background: #edf3ef;
}

.remaining-list,
.wall-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.remaining-chip,
.wall-chip {
  padding: 5px 7px;
  border-radius: 999px;
  background: rgba(255, 253, 247, 0.9);
  color: var(--green);
  font-weight: 900;
  font-size: 0.76rem;
  line-height: 1;
}

.wall-man {
  background: #f8ece8;
  color: var(--red);
}

.wall-pin {
  background: #e9f1f6;
  color: var(--blue);
}

.wall-sou {
  background: #e7f2eb;
  color: var(--green);
}

.wall-dragon {
  background: #fbf2d7;
  color: #83610d;
}

.primary-button,
.secondary-button {
  min-height: 40px;
  border-radius: 7px;
  padding: 0 10px;
  border: 1px solid transparent;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  flex: 1;
  background: var(--green);
  color: white;
}

.secondary-button {
  background: #f1eadb;
  border-color: var(--line);
}

.details {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: #4a534f;
  line-height: 1.7;
}

.detail-drawer {
  display: grid;
  gap: 10px;
}

.detail-drawer summary {
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.88);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 900;
  font-size: 0.86rem;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(8, 28, 22, 0.16);
}

.detail-drawer[open] {
  gap: 10px;
}

.detail-drawer[open] summary {
  margin-bottom: 10px;
}

.detail-drawer[open] .made-groups {
  margin-bottom: 10px;
}

.mini-rules {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.mini-rules article {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: center;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.9);
}

.mini-rules strong {
  color: var(--red);
}

.mini-rules span {
  color: #424a46;
  line-height: 1.45;
}

@media (min-width: 660px) {
  .app-shell {
    padding: 20px 20px 28px;
    gap: 12px;
  }

  .play-area {
    grid-template-columns: 92px 1fr;
  }

  .drawn-tile-wrap {
    display: grid;
    justify-items: center;
    gap: 6px;
  }

  .hand {
    grid-template-columns: repeat(14, minmax(36px, 1fr));
    gap: 8px;
  }

  .drawn {
    width: 76px;
  }

  .mini-rules {
    grid-template-columns: repeat(3, 1fr);
  }

  .mini-rules article {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

@media (max-width: 659px) {
  .top-tag {
    margin-left: auto;
    padding: 4px 8px;
    border: 1px solid rgba(255, 253, 247, 0.2);
    border-radius: 999px;
    background: rgba(255, 253, 247, 0.13);
    color: rgba(255, 253, 247, 0.92);
    font-size: 0.68rem;
    font-weight: 900;
    white-space: nowrap;
  }

  .app-shell {
    padding: 8px 8px 16px;
    gap: 7px;
  }

  h1 {
    font-size: clamp(0.98rem, 4.1vw, 1.45rem);
    line-height: 1.05;
  }

  h2 {
    font-size: 0.96rem;
  }

  .icon-button {
    width: auto;
    height: 38px;
    min-width: 88px;
    padding: 0 10px;
    font-size: 0.76rem;
  }

  .goal-band {
    padding: 4px 8px;
    border-left-width: 4px;
    border-radius: 7px;
  }

  .goal-label,
  .kicker,
  .drawn-tile-wrap p {
    font-size: 0.64rem;
    margin-bottom: 2px;
  }

  .goal-text {
    font-size: clamp(0.78rem, 3.2vw, 1.02rem);
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .progress-strip {
    gap: 4px;
    margin-top: 4px;
  }

  .progress-strip span {
    min-height: 20px;
    padding: 3px 4px;
    border-radius: 5px;
    font-size: 0.66rem;
  }

  .goal-sub {
    display: none;
  }

  .play-area {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 4px;
    align-items: end;
    padding: 7px 6px 8px;
  }

  .drawn-tile-wrap {
    grid-column: 1 / span 2;
    grid-row: 1;
    display: grid;
    justify-items: center;
    gap: 2px;
  }

  .hand {
    grid-column: 3 / span 6;
    grid-row: 1 / span 2;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
  }

  .hand .tile:nth-child(n + 7) {
    transform: translateX(calc(-100% - 4px));
  }

  .tile {
    min-height: 56px;
    border-radius: 6px;
    background:
      url("./assets/tile-base.png") center / 132% 116% no-repeat,
      linear-gradient(180deg, #fffef9 0%, #fdf9ee 54%, #eadfc7 100%);
    box-shadow: 4px 6px 10px rgba(3, 20, 15, 0.34);
  }

  .tile-symbol {
    padding: 8px 3px 4px;
  }

  .tile::before {
    inset: 8px 5px 5px;
  }

  .tile-number {
    font-size: clamp(1.16rem, 6.6vw, 1.98rem);
  }

  .tile-suit {
    font-size: 0.5rem;
  }

  .pin-dot {
    width: 12px;
    height: 12px;
  }

  .bamboo-mark span {
    width: 7px;
    height: 18px;
  }

  .dragon-tile .tile-number {
    font-size: clamp(1.45rem, 8vw, 2.22rem);
    transform: translateX(-0.16em);
  }

  .drawn {
    width: 40px;
    min-height: 56px;
    outline-width: 2px;
    outline-offset: 2px;
  }

  .teacher-panel {
    padding: 8px;
  }

  .teacher-head {
    gap: 8px;
  }

  .badge {
    padding: 4px 7px;
    font-size: 0.66rem;
  }

  .teacher-reason {
    margin: 6px 0;
    font-size: 0.76rem;
    line-height: 1.35;
  }

  .teacher-reason ul {
    padding-left: 1.1em;
  }

  .teacher-reason li + li {
    margin-top: 1px;
  }

  .remaining-panel,
  .wall-panel {
    margin: 6px 0 7px;
    padding: 6px 7px;
    border-radius: 6px;
  }

  .remaining-list,
  .wall-list {
    gap: 5px;
  }

  .remaining-chip,
  .wall-chip {
    padding: 4px 6px;
    font-size: 0.68rem;
  }

  .primary-button,
  .secondary-button {
    min-height: 34px;
    border-radius: 6px;
    padding: 0 8px;
    font-size: 0.82rem;
  }
}

@media (max-width: 659px) {
  .play-area {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    grid-template-rows: repeat(2, auto);
    column-gap: 4px;
    row-gap: 6px;
  }

  .drawn-tile-wrap {
    grid-column: 1 / span 2;
    grid-row: 1;
    align-self: end;
  }

  .hand {
    display: contents;
  }

  .hand .tile {
    transform: none;
  }

  .hand .tile:nth-child(1) {
    grid-column: 3;
    grid-row: 1;
  }

  .hand .tile:nth-child(2) {
    grid-column: 4;
    grid-row: 1;
  }

  .hand .tile:nth-child(3) {
    grid-column: 5;
    grid-row: 1;
  }

  .hand .tile:nth-child(4) {
    grid-column: 6;
    grid-row: 1;
  }

  .hand .tile:nth-child(5) {
    grid-column: 7;
    grid-row: 1;
  }

  .hand .tile:nth-child(6) {
    grid-column: 8;
    grid-row: 1;
  }

  .hand .tile:nth-child(7) {
    grid-column: 2;
    grid-row: 2;
  }

  .hand .tile:nth-child(8) {
    grid-column: 3;
    grid-row: 2;
  }

  .hand .tile:nth-child(9) {
    grid-column: 4;
    grid-row: 2;
  }

  .hand .tile:nth-child(10) {
    grid-column: 5;
    grid-row: 2;
  }

  .hand .tile:nth-child(11) {
    grid-column: 6;
    grid-row: 2;
  }

  .hand .tile:nth-child(12) {
    grid-column: 7;
    grid-row: 2;
  }

  .hand .tile:nth-child(13) {
    grid-column: 8;
    grid-row: 2;
  }

  .dragon-tile .tile-number {
    width: 100%;
    display: grid;
    place-items: center;
    text-align: center;
    transform: translateX(-0.16em);
    padding: 0;
  }
}
