html {
  color-scheme: light;
  background: #f4f1e8;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #fffdf7 0%, #f4f1e8 58%, #eaf3f1 100%);
  color: #202327;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
select,
input {
  font: inherit;
}

a {
  color: #17767c;
  font-weight: 850;
}

.app {
  width: min(100% - 20px, 980px);
  margin: 0 auto;
  padding: 12px 0 24px;
}

.top-nav,
.page-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  color: #68707a;
  font-size: 0.86rem;
}

.top-nav {
  margin-bottom: 10px;
  padding: 8px 0;
}

.top-nav strong {
  margin-right: auto;
  color: #202327;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.lang-select {
  min-height: 34px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fffdf8;
  color: #202327;
  font-weight: 850;
}

.screen,
.is-hidden {
  display: none !important;
}

.start-screen {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
  margin-bottom: 18px;
  padding: clamp(16px, 4vw, 28px);
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 14px 32px rgba(42, 42, 48, 0.08);
}

.game-shell {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 12px;
  align-items: start;
}

.play-area,
.side-panel,
.modal-card {
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 14px 32px rgba(42, 42, 48, 0.08);
}

.play-area {
  position: relative;
  padding: 12px;
  transition: box-shadow 180ms ease, transform 180ms ease;
}

.play-area.result-open .hud,
.play-area.result-open .tower-board,
.play-area.result-open .palette {
  filter: blur(4px);
  pointer-events: none;
}

.play-area.stage-flash {
  animation: stageFlash 420ms ease;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stat {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fffaf0;
}

.stat span {
  display: block;
  color: #68707a;
  font-size: 0.72rem;
  font-weight: 850;
}

.stat strong {
  display: block;
  color: #202327;
  font-size: clamp(1rem, 4vw, 1.45rem);
  line-height: 1.05;
}

.tower-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: stretch;
}

.tower-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  padding: 10px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fffdf8;
}

.tower-card h2 {
  margin: 0 0 8px;
  color: #68707a;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.tower {
  --tower-column-size: minmax(46px, 62px);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--tower-column-size);
  gap: 8px;
  align-items: end;
  justify-content: center;
  height: 344px;
  min-height: 344px;
  padding: 10px 10px 8px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(180deg, transparent 0 46px, rgba(32, 35, 39, 0.035) 46px 48px),
    linear-gradient(180deg, rgba(25, 114, 120, 0.05), rgba(25, 114, 120, 0)),
    #f8f3e8;
}

.column {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 100%;
  height: 100%;
  gap: 4px;
  padding: 6px 5px 5px;
  border: 2px dashed transparent;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), rgba(104, 112, 122, 0.18) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    rgba(255, 253, 248, 0.5);
  transition: background 130ms ease, border-color 130ms ease, transform 130ms ease;
}

.tower.editable .column.can-place {
  border-color: rgba(25, 114, 120, 0.42);
  background: rgba(25, 114, 120, 0.08);
}

.tower.editable .column.drop-hover {
  border-color: #17767c;
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), rgba(25, 114, 120, 0.34) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    rgba(25, 114, 120, 0.12);
  transform: translateY(-2px);
}

.drop-zone {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border: 2px dashed rgba(25, 114, 120, 0.5);
  border-radius: 8px;
  color: #17767c;
  background: rgba(255, 253, 248, 0.72);
  font-size: 1.2rem;
  font-weight: 950;
  order: 0;
  cursor: copy;
  transition: transform 120ms ease, background 120ms ease;
}

.tower:not(.editable) .drop-zone {
  visibility: hidden;
}

.drop-zone.full {
  display: none;
  border-color: rgba(104, 112, 122, 0.25);
  color: rgba(104, 112, 122, 0.35);
  background: rgba(255, 253, 248, 0.32);
}

.tower-base {
  width: calc(100% + 8px);
  height: 10px;
  margin: 2px -4px 0;
  border-radius: 999px;
  background: #d8cbb5;
  box-shadow: inset 0 -3px 0 rgba(75, 66, 52, 0.12), 0 3px 7px rgba(55, 48, 38, 0.1);
  order: 99;
}

.column-labels {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(42px, 1fr);
  gap: 6px;
  justify-content: center;
  padding: 6px 8px 0;
  color: #68707a;
  font-size: 0.76rem;
  font-weight: 900;
  text-align: center;
}

.block {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid rgba(32, 35, 39, 0.12);
  border-radius: 8px;
  color: #fff;
  font-size: clamp(1.1rem, 4vw, 1.55rem);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.16);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.08), 0 4px 8px rgba(55, 48, 38, 0.08);
  user-select: none;
  touch-action: none;
  flex: 0 0 auto;
  transition: transform 120ms ease, filter 120ms ease, opacity 120ms ease;
}

.block span {
  display: none;
}

.tower.editable .block {
  cursor: pointer;
}

.tower.editable .block.cut-preview,
.tower.editable .block:hover {
  outline: 3px solid #c44536;
  transform: translateY(-1px);
}

.tower.editable .block.cutting {
  animation: cutFall 190ms ease forwards;
  animation-delay: var(--cut-delay, 0ms);
}

.block.placed {
  animation: placePop 220ms cubic-bezier(0.2, 1.7, 0.45, 1);
}

.block.square {
  background: #17767c;
}

.block.circle {
  background: #c44536;
  border-radius: 50%;
}

.block.triangle {
  background: #3f5f9f;
  clip-path: polygon(50% 5%, 95% 92%, 5% 92%);
}

.block.diamond {
  background: #8a5fbf;
  border-radius: 0;
  clip-path: polygon(50% 4%, 96% 50%, 50% 96%, 4% 50%);
}

.palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 10px;
  padding: 8px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fff8ea;
}

.palette-button {
  display: grid;
  place-items: center;
  min-height: 54px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fffdf8;
  cursor: grab;
  touch-action: none;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.palette-shortcut {
  display: none;
  color: #68707a;
  font-size: 0.72rem;
  font-weight: 950;
  line-height: 1;
}

.palette-button:active {
  cursor: grabbing;
  transform: scale(0.96);
}

.palette-button[aria-pressed="true"] {
  border-color: #17767c;
  box-shadow: 0 0 0 3px rgba(25, 114, 120, 0.18);
}

.palette-button .block {
  width: 34px;
}

@media (min-width: 761px) {
  .palette-button {
    grid-template-rows: 1fr auto;
    gap: 5px;
    min-height: 66px;
    padding: 7px 6px 6px;
  }

  .palette-shortcut {
    display: block;
  }
}

.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  width: 56px;
  pointer-events: none;
  opacity: 0.94;
  filter: drop-shadow(0 10px 18px rgba(32, 35, 39, 0.2));
}

.side-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  align-content: start;
}

.message {
  min-height: 44px;
  padding: 10px;
  border-radius: 8px;
  background: #e8f4f2;
  color: #17767c;
  font-weight: 900;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button {
  min-height: 44px;
  border: 1px solid #17767c;
  border-radius: 8px;
  background: #17767c;
  color: #fff;
  cursor: pointer;
  font-weight: 950;
}

.button.secondary {
  background: #fffdf8;
  color: #17767c;
}

.button.danger {
  border-color: #c44536;
  background: #fffdf8;
  color: #c44536;
}

.start-title {
  margin: 0 0 10px;
  font-size: clamp(2.2rem, 8vw, 4rem);
  line-height: 0.95;
}

.start-copy .lead {
  margin: 0;
  color: #4f5965;
  font-size: clamp(1rem, 2.5vw, 1.18rem);
  font-weight: 780;
}

.intro-action-row,
.share-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 0;
}

.intro-duration {
  display: grid;
  gap: 6px;
  color: #68707a;
  font-size: 0.8rem;
  font-weight: 900;
}

.intro-duration select {
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fffdf8;
  color: #202327;
  font-weight: 950;
}

.share-actions {
  grid-template-columns: repeat(3, 1fr);
  margin-top: 8px;
}

.rule-column {
  display: grid;
  gap: 8px;
}

.start-screen > .leaderboard-panel {
  width: 100%;
  box-sizing: border-box;
}

.rule-card,
.leaderboard-panel,
.result-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fffdf8;
}

.rule-card {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
}

.rule-card p {
  display: grid;
  gap: 4px;
  margin: 0;
}

.rule-card b {
  color: #202327;
  font-size: 1rem;
}

.rule-card span {
  color: #4f5965;
  font-size: 0.9rem;
  font-weight: 850;
}

.rule-art {
  position: relative;
  display: grid;
  place-items: end center;
  width: 72px;
  min-height: 92px;
  margin: 0 auto;
  padding: 6px 5px 5px;
  border: 3px solid #5e6472;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(94, 100, 114, 0.16) 1px, transparent 1px) 0 0 / 33.333% 25%,
    linear-gradient(180deg, rgba(94, 100, 114, 0.16) 1px, transparent 1px) 0 0 / 33.333% 25%,
    #fffaf0;
  box-shadow: inset 0 0 0 1px rgba(255, 253, 248, 0.86);
}

.compare-art,
.cut-art {
  grid-template-columns: 1fr 14px 1fr;
  gap: 3px;
}

.place-art {
  grid-template-rows: auto 14px auto;
  align-content: center;
  gap: 4px;
}

.rule-tower {
  display: grid;
  align-content: end;
  justify-items: center;
  gap: 3px;
  min-height: 50px;
  padding: 2px;
  border-radius: 6px;
  background: rgba(255, 253, 248, 0.66);
}

.rule-tower .block,
.rule-palette .block {
  width: 13px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.08), 0 2px 4px rgba(55, 48, 38, 0.08);
}

.rule-palette {
  display: flex;
  justify-content: center;
  gap: 3px;
  padding: 4px;
  border: 1px solid rgba(215, 207, 191, 0.9);
  border-radius: 7px;
  background: rgba(255, 253, 248, 0.78);
}

.rule-arrow,
.rule-drop {
  color: #17767c;
  font-size: 0.82rem;
  font-weight: 950;
  align-self: center;
  justify-self: center;
}

.cut-mark {
  outline: 3px solid #c44536;
  outline-offset: 2px;
}

.result-overlay {
  position: absolute;
  inset: 8px;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 8px;
  background: rgba(248, 243, 232, 0.68);
  backdrop-filter: blur(2px);
}

.result-card {
  display: grid;
  gap: 8px;
  width: min(100%, 430px);
  max-height: min(94dvh, 640px);
  overflow: auto;
  box-shadow: 0 18px 38px rgba(42, 42, 48, 0.18);
}

.result-card h2 {
  margin: 0 0 10px;
  line-height: 1.08;
}

.field {
  display: grid;
  gap: 5px;
  color: #68707a;
  font-size: 0.78rem;
  font-weight: 900;
}

.field input {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fffaf0;
  color: #202327;
  font-weight: 850;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.result-grid div {
  padding: 10px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fffdf8;
}

.result-grid span {
  display: block;
  color: #68707a;
  font-size: 0.75rem;
  font-weight: 850;
}

.result-grid strong {
  display: block;
  font-size: 1.25rem;
}

.leaderboard-title {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: baseline;
  color: #68707a;
  font-size: 0.8rem;
  font-weight: 850;
}

.leaderboard-title strong {
  color: #202327;
  font-size: 1rem;
}

.leaderboard-list {
  display: grid;
  gap: 5px;
  max-height: 162px;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow: auto;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 7px 8px;
  border: 1px solid #d7cfbf;
  border-radius: 8px;
  background: #fffaf0;
  font-weight: 850;
}

.leaderboard-list .rank,
.leaderboard-list .score-value {
  color: #17767c;
  font-weight: 950;
}

.leaderboard-list .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list .own {
  border-color: #17767c;
  background: #e8f4f2;
}

.status-note {
  min-height: 1.1em;
  margin: 0;
  color: #68707a;
  font-size: 0.78rem;
  font-weight: 800;
}

.status-note.error {
  color: #c44536;
}

.page-footer {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid rgba(215, 207, 191, 0.8);
}

@media (max-width: 760px) {
  .app {
    width: min(100% - 10px, 560px);
    padding-top: 4px;
  }

  .app:has(#gameView:not(.is-hidden)) {
    min-height: calc(100dvh - 8px);
    padding-bottom: 4px;
    display: grid;
    align-content: center;
  }

  .app:has(#gameView:not(.is-hidden)) .top-nav,
  .app:has(#gameView:not(.is-hidden)) .page-footer {
    display: none;
  }

  .game-shell {
    grid-template-columns: 1fr;
    gap: 6px;
    min-height: 0;
    align-content: start;
  }

  .start-screen {
    grid-template-columns: 1fr;
    padding: 14px;
    gap: 10px;
  }

  .rule-card {
    grid-template-columns: 78px minmax(0, 1fr);
    gap: 9px;
  }

  .rule-art {
    width: 64px;
    min-height: 82px;
    padding: 5px 4px 4px;
  }

  .rule-tower {
    min-height: 42px;
  }

  .rule-tower .block,
  .rule-palette .block {
    width: 12px;
  }

  .start-title {
    margin-bottom: 6px;
    font-size: clamp(1.95rem, 11vw, 2.6rem);
  }

  .start-copy .lead {
    font-size: 0.95rem;
  }

  .rule-card b {
    font-size: 0.92rem;
  }

  .rule-card span {
    font-size: 0.8rem;
  }

  .hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    margin-bottom: 6px;
  }

  .stat {
    padding: 5px 6px;
  }

  .stat span {
    font-size: 0.62rem;
  }

  .tower-board {
    gap: 5px;
  }

  .play-area,
  .side-panel {
    padding: 6px;
  }

  .tower-card {
    padding: 5px;
  }

  .tower-card h2 {
    margin-bottom: 4px;
    font-size: 0.66rem;
  }

  .tower {
    --tower-column-size: minmax(34px, 42px);
    grid-auto-columns: var(--tower-column-size);
    justify-self: center;
    width: fit-content;
    max-width: 100%;
    box-sizing: border-box;
    gap: 4px;
    height: min(42dvh, 280px);
    min-height: 258px;
    padding: 5px;
    overflow: hidden;
  }

  .column-labels {
    display: none;
  }

  .column {
    gap: 3px;
    min-width: 0;
    padding: 3px 2px;
  }

  .drop-zone {
    aspect-ratio: auto;
    min-height: 24px;
    max-height: 28px;
    border-width: 1px;
    font-size: 0.9rem;
  }

  .drop-zone.full {
    display: none;
  }

  .block {
    border-radius: 6px;
    border-width: 1px;
    font-size: clamp(0.9rem, 5vw, 1.25rem);
    min-height: 0;
  }

  .palette {
    margin-top: 6px;
    padding: 5px;
    gap: 5px;
  }

  .palette-button {
    min-height: 42px;
  }

  .palette-button .block {
    width: 30px;
  }

  .side-panel {
    grid-template-columns: minmax(0, 1fr) minmax(150px, 0.9fr);
    align-items: stretch;
    gap: 6px;
    box-shadow: none;
  }

  .top-nav strong {
    flex-basis: 100%;
  }

  .top-nav {
    margin-bottom: 6px;
    gap: 5px 9px;
    font-size: 0.78rem;
  }

  .message {
    min-height: 38px;
    padding: 8px;
    font-size: 0.86rem;
  }

  .button {
    min-height: 40px;
  }

  .result-overlay {
    inset: 6px;
    align-items: start;
    padding: 6px;
  }

  .result-card {
    gap: 6px;
    max-height: calc(100dvh - 26px);
    padding: 8px;
  }

  .result-grid {
    gap: 6px;
    margin: 0;
  }

  .result-grid div {
    padding: 6px;
  }

  .leaderboard-list {
    max-height: 128px;
  }

  .share-actions {
    gap: 6px;
  }

}

@keyframes placePop {
  0% { transform: translateY(-14px) scale(0.72); opacity: 0; }
  70% { transform: translateY(2px) scale(1.08); opacity: 1; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes cutFall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(-22px) rotate(8deg); opacity: 0; }
}

@keyframes stageFlash {
  0% { box-shadow: 0 0 0 rgba(25, 114, 120, 0); }
  35% { box-shadow: 0 0 0 6px rgba(25, 114, 120, 0.18), 0 0 34px rgba(25, 114, 120, 0.22); }
  100% { box-shadow: 0 14px 32px rgba(42, 42, 48, 0.08); }
}
