:root {
  --bg-deep: #11211f;
  --bg-mid: #20423f;
  --panel: rgba(245, 239, 230, 0.96);
  --panel-soft: rgba(255, 250, 244, 0.92);
  --ink: #1f1813;
  --muted: #67574d;
  --line: rgba(40, 31, 25, 0.12);
  --accent: #d3a151;
  --accent-deep: #bf6b3f;
  --jade: #2f6b58;
  --tile-cream: #fffaf0;
  --tile-edge: #efe3cc;
  --tile-shadow: rgba(17, 19, 20, 0.22);
  --shadow: 0 22px 56px rgba(8, 10, 13, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 12%, rgba(211, 161, 81, 0.16), transparent 22%),
    radial-gradient(circle at 84% 14%, rgba(69, 132, 116, 0.18), transparent 24%),
    linear-gradient(150deg, var(--bg-deep), var(--bg-mid));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.026), transparent 28%),
    linear-gradient(rgba(255, 255, 255, 0.014) 0, rgba(255, 255, 255, 0.014) 1px, transparent 1px, transparent 76px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.014) 0, rgba(255, 255, 255, 0.014) 1px, transparent 1px, transparent 76px);
  opacity: 0.34;
  pointer-events: none;
}

.mahjong-app {
  width: min(1240px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.mahjong-topbar,
.mahjong-controls,
.board-panel,
.selection-card,
.rules-card {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.mahjong-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-radius: 24px;
}

.mahjong-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mahjong-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: var(--ink);
}

.mahjong-brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #23150f;
  font-weight: 900;
}

.mahjong-brand-copy {
  display: grid;
  gap: 2px;
}

.mahjong-brand-copy strong {
  font-size: 1.04rem;
}

.mahjong-brand-copy span {
  color: var(--muted);
  font-size: 0.92rem;
}

.mahjong-return,
.mahjong-support,
.action-button,
.mahjong-tile {
  font: inherit;
}

.mahjong-return,
.mahjong-support,
.action-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 46px;
  padding: 0 18px;
  border: 1px solid rgba(36, 25, 18, 0.12);
  border-radius: 999px;
  background: linear-gradient(145deg, #fffaf3, #ecdcc6);
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, background 140ms ease;
}

.action-button.primary {
  background: linear-gradient(145deg, var(--accent), var(--accent-deep));
  color: #23150f;
}

.mahjong-support {
  background: linear-gradient(145deg, #ffdc42, #f0b90a);
  color: #23150f;
}

.mahjong-return:hover,
.mahjong-return:focus-visible,
.mahjong-support:hover,
.mahjong-support:focus-visible,
.action-button:hover,
.action-button:focus-visible,
.mahjong-tile:hover,
.mahjong-tile:focus-visible {
  transform: translateY(-1px);
}

.action-button:disabled {
  opacity: 0.52;
  cursor: not-allowed;
  transform: none;
}

.mahjong-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(360px, 1.08fr);
  gap: 20px;
  align-items: start;
  padding: 28px 0 18px;
}

.eyebrow {
  margin: 0 0 12px;
  color: rgba(255, 247, 235, 0.8);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.mahjong-copy h1,
.mahjong-status h2,
.selection-card h3,
.rules-card h3,
.result-overlay h2 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
}

.mahjong-copy h1 {
  margin: 0 0 14px;
  max-width: 12ch;
  color: #fff7eb;
  font-size: clamp(2.3rem, 5vw, 4.4rem);
  line-height: 0.95;
}

.mahjong-copy p:last-child {
  margin: 0;
  max-width: 60ch;
  color: rgba(255, 244, 231, 0.84);
  line-height: 1.65;
}

.mahjong-controls {
  border-radius: 30px;
  padding: 22px;
}

.mahjong-status h2 {
  margin: 0;
  font-size: clamp(1.26rem, 2.4vw, 1.82rem);
  line-height: 1.12;
}

.notice-text,
.selection-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.58;
}

.setup-row {
  display: grid;
  margin-top: 18px;
}

.setup-label {
  margin: 0 0 10px;
  color: #584635;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.difficulty-select {
  min-height: 48px;
  width: 100%;
  padding: 0 14px;
  border: 1px solid rgba(36, 25, 18, 0.12);
  border-radius: 16px;
  background: #fbf4ea;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.metric-card {
  padding: 14px;
  border: 1px solid rgba(36, 25, 18, 0.1);
  border-radius: 20px;
  background: var(--panel-soft);
}

.metric-card span {
  display: block;
  margin-bottom: 6px;
  color: #786452;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 1.28rem;
}

.control-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.mahjong-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.28fr) minmax(300px, 0.72fr);
  gap: 20px;
  align-items: start;
}

.board-panel {
  position: relative;
  border-radius: 34px;
  padding: 20px;
  background:
    radial-gradient(circle at 24% 18%, rgba(255, 233, 191, 0.12), transparent 18%),
    radial-gradient(circle at 78% 26%, rgba(199, 105, 192, 0.18), transparent 24%),
    linear-gradient(155deg, #4c1458, #261032 58%, #1a1d30);
  min-height: 680px;
  overflow: hidden;
}

.board-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 10% 70%, rgba(255, 0, 212, 0.14), transparent 20%),
    radial-gradient(circle at 90% 22%, rgba(255, 255, 255, 0.08), transparent 14%),
    linear-gradient(rgba(255, 255, 255, 0.03) 0, rgba(255, 255, 255, 0.03) 1px, transparent 1px, transparent 86px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 0, rgba(255, 255, 255, 0.03) 1px, transparent 1px, transparent 86px);
  opacity: 0.55;
  pointer-events: none;
}

.board-scroll {
  overflow: auto;
  padding: 6px;
  position: relative;
  z-index: 1;
}

.mahjong-board {
  position: relative;
  min-width: 100%;
  min-height: 560px;
}

.mahjong-tile {
  position: absolute;
  width: 86px;
  height: 108px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.tile-left-edge,
.tile-bottom-edge,
.tile-surface,
.tile-mark {
  position: absolute;
  display: block;
  pointer-events: none;
}

.tile-left-edge {
  left: 0;
  top: 10px;
  bottom: 12px;
  width: 12px;
  border-radius: 14px 0 0 14px;
  background:
    linear-gradient(180deg, #8cc84a, #4d8f29 58%, #2f611c);
  box-shadow:
    inset -2px 0 0 rgba(13, 29, 15, 0.22),
    0 12px 18px rgba(10, 12, 14, 0.18);
}

.tile-bottom-edge {
  left: 10px;
  right: 0;
  bottom: 0;
  height: 12px;
  border-radius: 0 0 16px 12px;
  background:
    linear-gradient(180deg, #ffcb42, #f0a70d 52%, #cc7d0b);
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 214, 0.34),
    0 14px 18px rgba(10, 12, 14, 0.2);
}

.tile-surface {
  left: 10px;
  right: 0;
  top: 0;
  bottom: 12px;
  border-radius: 16px;
  background:
    linear-gradient(145deg, #fff7df, #f3ddb1 58%, #e6c98b);
  box-shadow:
    0 14px 24px var(--tile-shadow),
    inset 0 0 0 1px rgba(92, 69, 44, 0.16);
  overflow: hidden;
}

.tile-surface::before,
.tile-surface::after {
  content: "";
  position: absolute;
  border-radius: 12px;
}

.tile-surface::before {
  inset: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 248, 228, 0.72)),
    linear-gradient(145deg, #fffdf4, #f9ecc7);
  box-shadow: inset 0 0 0 1px rgba(103, 80, 52, 0.08);
}

.tile-surface::after {
  inset: 6px;
  background:
    radial-gradient(circle at 20% 16%, rgba(255, 255, 255, 0.54), transparent 24%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.24), transparent 34%);
}

.mahjong-tile.free .tile-surface {
  transform: translateY(-1px);
}

.mahjong-tile.blocked {
  opacity: 0.72;
  filter: saturate(0.76);
}

.mahjong-tile.selected .tile-surface {
  box-shadow:
    0 14px 24px var(--tile-shadow),
    inset 0 0 0 3px rgba(211, 161, 81, 0.92);
}

.mahjong-tile.hinted .tile-surface {
  box-shadow:
    0 14px 24px var(--tile-shadow),
    inset 0 0 0 3px rgba(86, 152, 119, 0.92);
}

.mahjong-tile.last-removed .tile-surface {
  animation: tile-flash 720ms ease both;
}

.tile-mark {
  inset: 14px 12px 18px 12px;
  z-index: 1;
}

.tile-grid-mark {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  place-items: center;
}

.tile-pip {
  display: block;
}

.circle-pip {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(25, 29, 36, 0.16);
  background:
    radial-gradient(circle at 34% 34%, rgba(255, 255, 255, 0.88), rgba(255, 255, 255, 0.12) 38%, transparent 40%),
    radial-gradient(circle at center, currentColor 0 48%, transparent 52%),
    radial-gradient(circle at center, transparent 0 68%, currentColor 72% 100%);
  color: #245db7;
}

.bamboo-pip {
  width: 12px;
  height: 28px;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.44), transparent 24%),
    linear-gradient(180deg, currentColor, currentColor);
  box-shadow:
    inset 0 -5px 0 rgba(0, 0, 0, 0.12),
    inset 0 4px 0 rgba(255, 255, 255, 0.18);
  color: #1f7a35;
}

.color-1 {
  color: #1e47ad;
}

.color-2 {
  color: #ab2f34;
}

.count-1 .circle-pip {
  width: 26px;
  height: 26px;
}

.count-1 .bamboo-pip {
  width: 16px;
  height: 40px;
}

.tile-character-mark,
.tile-glyph-mark {
  display: grid;
  justify-items: center;
  align-content: center;
}

.tile-character-mark {
  gap: 4px;
}

.tile-character-number {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: 3.25rem;
  line-height: 1;
  font-weight: 900;
  color: #111111;
}

.tile-character-suffix {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: 2.5rem;
  line-height: 0.9;
  font-weight: 900;
  color: #b13836;
}

.tile-glyph {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  font-size: 3.55rem;
  line-height: 1;
  font-weight: 900;
}

.wind-mark .tile-glyph {
  color: #2356b5;
}

.dragon-mark .tile-glyph {
  color: #111111;
}

.dragon-red .tile-glyph {
  color: #b1221a;
}

.dragon-green .tile-glyph {
  color: #197133;
}

.flower-mark .tile-glyph {
  color: #b34e4a;
}

.season-mark .tile-glyph {
  color: #2b4ea9;
}

.tile-subtitle {
  margin-top: 2px;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(55, 42, 31, 0.52);
}

@keyframes tile-flash {
  0% {
    transform: scale(0.96);
    opacity: 0.78;
  }

  55% {
    transform: scale(1.04);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.result-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(92%, 420px);
  padding: 22px 20px 18px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 249, 241, 0.97), rgba(253, 244, 232, 0.98)),
    var(--panel);
  text-align: center;
  box-shadow: 0 22px 48px rgba(12, 5, 2, 0.36);
  z-index: 20;
}

.result-overlay[hidden] {
  display: none;
}

.overlay-kicker {
  margin: 0 0 6px;
  color: #7c654f;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.result-overlay h2 {
  margin: 0 0 10px;
  font-size: clamp(1.7rem, 3vw, 2.2rem);
  line-height: 1;
}

.overlay-message {
  margin: 0 auto;
  max-width: 30ch;
  color: var(--muted);
  line-height: 1.58;
}

.overlay-stats,
.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.overlay-stats span {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 999px;
  background: #f4e9da;
  color: #594537;
  font-weight: 700;
}

.mahjong-sidebar {
  display: grid;
  gap: 16px;
}

.selection-card,
.rules-card {
  border-radius: 28px;
  padding: 18px;
}

.selection-card {
  background:
    linear-gradient(165deg, rgba(255, 255, 255, 0.34), transparent 46%),
    var(--panel);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.selection-card h3,
.rules-card h3 {
  margin: 0;
  font-size: 1.26rem;
}

.card-head span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.rules-list {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.rules-list li {
  color: var(--muted);
  line-height: 1.58;
  padding-left: 18px;
  position: relative;
}

.rules-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  transform: translateY(-50%);
}

@media (max-width: 1120px) {
  .mahjong-hero,
  .mahjong-layout {
    grid-template-columns: 1fr;
  }

  .mahjong-copy h1 {
    max-width: none;
  }
}

@media (max-width: 760px) {
  .mahjong-app {
    width: min(100%, calc(100% - 20px));
    padding-top: 14px;
  }

  .mahjong-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .mahjong-topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .mahjong-topbar-actions > * {
    flex: 1 1 0;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-row {
    flex-direction: column;
  }

  .control-row .action-button {
    width: 100%;
  }

  .board-panel,
  .mahjong-controls,
  .selection-card,
  .rules-card {
    padding: 16px;
  }

  .mahjong-tile {
    transform: scale(0.88);
    transform-origin: top left;
  }
}
