:root {
  color-scheme: light;
  --page: #f6f2ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #26302f;
  --muted: #69716d;
  --line: #d8ddd2;
  --teal: #1c9a93;
  --coral: #ed6b5f;
  --yellow: #f7c948;
  --shadow: 0 14px 36px rgba(38, 48, 47, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(28, 154, 147, 0.12), transparent 32%),
    linear-gradient(220deg, rgba(237, 107, 95, 0.14), transparent 30%),
    var(--page);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--yellow);
  box-shadow: 5px 5px 0 var(--ink);
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.tab-button,
.small-button,
.level-button,
.tool-button,
.primary-button,
.secondary-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  cursor: pointer;
  transition:
    box-shadow 120ms ease,
    background 120ms ease,
    border-color 120ms ease,
    color 120ms ease;
}

.tab-button {
  min-width: 64px;
  min-height: 34px;
  padding: 0 14px;
}

.tab-button.is-active,
.primary-button {
  border-color: var(--ink);
  background: var(--teal);
  color: #fff;
}

.tab-button:not(:disabled):hover,
.small-button:not(:disabled):hover,
.level-button:not(:disabled):hover,
.tool-button:not(:disabled):hover,
.primary-button:not(:disabled):hover,
.secondary-button:not(:disabled):hover {
  border-color: rgba(38, 48, 47, 0.62);
  box-shadow: 0 6px 16px rgba(38, 48, 47, 0.12);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.play-column,
.side-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.play-column {
  padding: 14px;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stats-strip div {
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.stats-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stats-strip strong {
  display: block;
  margin-top: 2px;
  font-size: 22px;
  line-height: 1.1;
}

.board-wrap {
  position: relative;
  overflow: hidden;
  border: 2px solid #33403d;
  border-radius: 8px;
  background:
    linear-gradient(rgba(38, 48, 47, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(38, 48, 47, 0.05) 1px, transparent 1px),
    #eaf6f2;
  background-size: 34px 34px;
  aspect-ratio: 1.34;
}

.board {
  position: absolute;
  inset: 0;
}

.tile {
  position: absolute;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  min-width: 56px;
  min-height: 48px;
  padding: 5px 4px 4px;
  border: 2px solid rgba(38, 48, 47, 0.7);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.35), transparent 42%),
    var(--tile-color);
  color: var(--tile-ink);
  box-shadow:
    0 8px 0 rgba(38, 48, 47, 0.22),
    0 14px 16px rgba(38, 48, 47, 0.16);
  backface-visibility: hidden;
  transform: translate3d(-50%, -50%, 0);
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease,
    filter 120ms ease;
  touch-action: manipulation;
  will-change: filter;
}

.tile:not(:disabled):hover {
  border-color: rgba(38, 48, 47, 0.9);
  box-shadow:
    0 8px 0 rgba(38, 48, 47, 0.24),
    0 16px 20px rgba(38, 48, 47, 0.18);
  filter: brightness(1.05);
  transform: translate3d(-50%, -50%, 0);
}

.tile:not(:disabled):active {
  box-shadow:
    0 5px 0 rgba(38, 48, 47, 0.24),
    0 10px 14px rgba(38, 48, 47, 0.16);
  transform: translate3d(-50%, -50%, 0);
}

.tile.is-available {
  outline: 2px solid rgba(255, 255, 255, 0.86);
  outline-offset: -5px;
}

.tile.is-blocked {
  filter: saturate(0.72) brightness(0.72);
}

.tile-symbol {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.22);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.tile-name {
  overflow: hidden;
  max-width: 100%;
  color: currentColor;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-row {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.slot-cell {
  display: grid;
  min-height: 56px;
  place-items: center;
  border: 2px dashed #aab6ae;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.slot-cell.is-filled {
  border-style: solid;
  border-color: rgba(38, 48, 47, 0.72);
  background: var(--tile-color);
  color: var(--tile-ink);
  box-shadow: inset 0 -6px 0 rgba(38, 48, 47, 0.12);
}

.slot-cell span {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  font-weight: 900;
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.tool-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  background: #fff;
  font-weight: 800;
}

.tool-icon {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 8px;
  background: #eef6f4;
  color: var(--teal);
  font-size: 20px;
  line-height: 1;
}

.side-panel {
  display: grid;
  gap: 16px;
  padding: 14px;
}

.panel-section {
  display: grid;
  gap: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title h2 {
  font-size: 18px;
}

.section-title span {
  padding: 4px 8px;
  border-radius: 8px;
  background: #e9f8f5;
  color: #116c67;
  font-size: 12px;
  font-weight: 800;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.level-button {
  min-height: 36px;
  background: #fff;
  font-weight: 800;
}

.level-button.is-active {
  border-color: var(--ink);
  background: var(--coral);
  color: #fff;
}

.my-rank {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid rgba(28, 154, 147, 0.28);
  border-radius: 8px;
  background: #eef8f6;
}

.my-rank strong {
  color: #116c67;
  font-size: 14px;
}

.my-rank span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style-position: inside;
}

.rank-list li {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.rank-list li.is-self {
  border-color: rgba(28, 154, 147, 0.45);
  background: #f0fbf9;
}

.rank-list strong {
  color: var(--coral);
}

.rank-list span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-list .empty-rank {
  display: block;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  max-width: min(360px, calc(100% - 32px));
  padding: 10px 14px;
  border-radius: 8px;
  background: rgba(38, 48, 47, 0.92);
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 28, 27, 0.52);
}

.modal-backdrop[hidden] {
  display: none;
}

.result-modal {
  width: min(380px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: var(--shadow);
}

.result-modal h2 {
  font-size: 24px;
}

.result-modal p {
  margin-top: 8px;
  color: var(--muted);
}

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

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 0 12px;
  font-weight: 800;
}

.secondary-button {
  background: #fff;
}

@media (max-width: 900px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    box-shadow: none;
  }
}

@media (max-width: 600px) {
  .app-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 10px;
  }

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

  h1 {
    font-size: 21px;
  }

  .mode-tabs {
    width: 100%;
  }

  .tab-button {
    flex: 1;
  }

  .play-column {
    padding: 10px;
  }

  .stats-strip strong {
    font-size: 20px;
  }

  .board-wrap {
    aspect-ratio: 0.86;
  }

  .tile {
    min-width: 42px;
    min-height: 40px;
    padding: 4px 3px;
  }

  .tile-symbol {
    width: 24px;
    height: 24px;
    font-size: 15px;
  }

  .tile-name {
    display: none;
  }

  .slot-row {
    gap: 5px;
  }

  .slot-cell {
    min-height: 44px;
  }

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