﻿:root {
  --page: #111111;
  --panel: #1f1f20;
  --panel-2: #2f2f33;
  --tile: #2b2b2c;
  --line: #3d3d3f;
  --text: #f2f2f2;
  --muted: #85858a;
  --green: #58ad4e;
  --yellow: #cdbc5b;
  --red: #df494b;
  --key: #333338;
  --key-dark: #0f0f10;
  --cell: clamp(31px, min(5.18vh, 6.55vw), 49px);
  --score-cell: clamp(33px, min(5.18vh, 6.85vw), 53px);
  --gap: clamp(3px, 0.48vh, 6px);
  --font: "Trebuchet MS", "Aptos", Verdana, sans-serif;
  --display-font: "Arial Black", Impact, "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100vw - 18px, 760px);
  height: 100dvh;
  margin: 0 auto;
  padding: clamp(6px, 1vh, 10px) 0;
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  gap: clamp(7px, 1.15vh, 12px);
}

.top-bar {
  height: clamp(54px, 8.7vh, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

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

.logo-frame {
  width: clamp(44px, 7.1vh, 62px);
  height: clamp(44px, 7.1vh, 62px);
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 0;
  background: transparent;
}

.logo-frame img,
.icon-control img,
.option-item img {
  object-fit: contain;
}

.logo-frame img {
  width: 112%;
  height: 112%;
}

.logo-fallback {
  color: #111;
  font-family: var(--display-font);
  font-size: 0.72rem;
  line-height: 0.86;
  letter-spacing: -0.05em;
  text-align: center;
}

.logo-frame img:not([hidden]) + .logo-fallback,
.icon-control img:not([hidden]) + span,
.option-item img:not([hidden]) + .option-symbol {
  display: none;
}

h1 {
  margin: 0;
  color: #e8e8e8;
  font-family: var(--display-font);
  font-size: clamp(1.18rem, 3.25vh, 1.85rem);
  letter-spacing: 0.025em;
  text-shadow: 2px 2px 0 #505055;
}

.top-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.menu-control {
  position: relative;
}

.icon-control {
  width: clamp(36px, 6.25vh, 50px);
  height: clamp(36px, 6.25vh, 50px);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  color: #ddd;
  background: var(--panel-2);
  font-size: clamp(1rem, 2.55vh, 1.42rem);
  font-weight: 900;
}

.icon-control img {
  width: 62%;
  height: 62%;
}

.option-toggle[aria-expanded="true"] {
  outline: 1px solid rgba(255, 255, 255, 0.24);
}

.icon-control:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.option-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 25;
  width: min(300px, calc(100vw - 24px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1d1d1f;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.45);
}

.option-item {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 34px 96px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 0;
  color: var(--text);
  background: transparent;
  text-align: left;
}

.option-item + .option-item {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.option-item.active,
.option-item:hover {
  background: rgba(255, 255, 255, 0.055);
}

.option-item img {
  width: 30px;
  height: 30px;
}

.control-symbol,
.option-symbol {
  display: grid;
  place-items: center;
  font-family: var(--display-font);
  font-size: 1.32rem;
  line-height: 1;
}

.control-symbol {
  width: 100%;
  height: 100%;
}

.green-symbol {
  color: var(--green);
}

.red-symbol {
  color: var(--red);
}

.option-item strong {
  font-size: 0.92rem;
}

.option-item small {
  color: #b2b2b8;
  font-size: 0.76rem;
}

#modeMenu .option-item {
  min-height: 46px;
  grid-template-columns: 34px 1fr;
  padding-block: 8px;
}

#modeMenu {
  width: 150px;
}

.game-stage {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, max-content);
  justify-items: center;
  align-content: start;
  gap: clamp(4px, 0.62vh, 7px);
}

.legend-panel {
  position: fixed;
  top: clamp(120px, 18vh, 174px);
  left: calc(50% + 300px);
  z-index: 18;
  width: 230px;
  padding: 16px 14px 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  color: var(--text);
  background:
    linear-gradient(145deg, rgba(47, 47, 51, 0.96), rgba(23, 23, 24, 0.96)),
    var(--panel);
  box-shadow: 0 20px 46px rgba(0, 0, 0, 0.42);
}

.legend-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  color: #f0f0f0;
  background: transparent;
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1;
}

.legend-close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.legend-panel h2 {
  margin: 0 32px 12px 0;
  color: #eeeeee;
  font-family: var(--display-font);
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-shadow: 1px 1px 0 #505055;
}

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

.legend-list li {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.legend-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--panel-2);
  font-family: var(--display-font);
  font-size: 1.22rem;
  font-weight: 950;
  line-height: 1;
}

.infinity-icon {
  color: #e7e7e7;
  font-size: 1.55rem;
}

.legend-list strong,
.legend-list small {
  display: block;
}

.legend-list strong {
  color: #f0f0f0;
  font-size: 0.88rem;
}

.legend-list small {
  margin-top: 2px;
  color: #b4b4ba;
  font-size: 0.74rem;
  line-height: 1.2;
}

.board-head {
  min-height: clamp(18px, 2.75vh, 25px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--muted);
  font-size: clamp(0.78rem, 1.72vh, 1rem);
  font-weight: 900;
  text-align: center;
}

.game-label {
  color: #dadada;
}

.status-text {
  color: #9f9fa5;
  max-width: 56vw;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.board {
  display: grid;
  gap: var(--gap);
  align-self: start;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, var(--cell)) repeat(3, var(--score-cell));
  gap: var(--gap);
  align-items: center;
}

.letters,
.score-boxes {
  display: contents;
}

.cell,
.score-box {
  width: 100%;
  height: var(--cell);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 5px;
  color: var(--text);
  font-family: var(--display-font);
  font-size: clamp(1rem, 3vh, 1.7rem);
  font-weight: 950;
  line-height: 1;
}

.cell {
  background: var(--tile);
}

.cell.filled {
  background: var(--tile);
}

.cell.note-green,
.score-box.green {
  background: var(--green);
}

.cell.note-yellow,
.score-box.yellow {
  background: var(--yellow);
}

.cell.note-red,
.score-box.red {
  background: var(--red);
}

.cell.can-note:hover {
  filter: brightness(1.1);
}

.score-box {
  color: #f5f5f5;
}

.cell.reveal-cell,
.score-box {
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

.cell.reveal-cell,
.score-box.reveal-score {
  animation: score-card-flip 540ms ease-in-out var(--flip-delay) both;
}

.keyboard-shell {
  width: 100%;
  padding: clamp(7px, 1vh, 10px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.keyboard {
  display: grid;
  gap: clamp(5px, 0.8vh, 8px);
  position: relative;
}

.key-row {
  display: grid;
  gap: clamp(4px, 0.7vw, 7px);
}

.key-row-top {
  grid-template-columns: repeat(12, 1fr) 1.15fr;
}

.key-row-mid {
  grid-template-columns: repeat(11, 1fr) 1.55fr;
  padding-left: clamp(0px, 3.7vw, 34px);
}

.key-row-bottom {
  grid-template-columns: repeat(9, 1fr);
  padding-inline: clamp(28px, 8.2vw, 82px) clamp(44px, 12vw, 112px);
}

.key-button {
  min-width: 0;
  height: clamp(32px, 5.25vh, 45px);
  border: 0;
  border-radius: 6px;
  color: #eeeeee;
  background: var(--key);
  font-family: var(--display-font);
  font-size: clamp(0.82rem, 1.9vh, 1rem);
  font-weight: 950;
  letter-spacing: 0.05em;
}

.key-button:hover {
  filter: brightness(1.13);
}

.key-button:active {
  transform: translateY(1px);
}

.action-key {
  color: #dedede;
  background: var(--key-dark);
  font-size: clamp(1.3rem, 3.2vh, 1.9rem);
}

.enter-key {
  color: #dcefe2;
}

.clear-notes-key {
  position: absolute;
  right: 0;
  bottom: 0;
  width: clamp(54px, 10.2vw, 78px);
  height: clamp(28px, 4.55vh, 39px);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 0;
  color: #dcefe2;
  background: var(--key-dark);
  font-size: clamp(0.56rem, 1.25vh, 0.72rem);
  line-height: 1.02;
  letter-spacing: 0.04em;
  text-align: center;
  z-index: 2;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: clamp(10px, 2vh, 18px);
  z-index: 30;
  max-width: min(92vw, 520px);
  padding: 11px 15px;
  border-radius: 9px;
  color: #fff;
  background: #2f2f33;
  border: 1px solid var(--line);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 0.9rem;
  font-weight: 900;
}

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

@keyframes score-card-flip {
  0% {
    color: transparent;
    transform: rotateX(0deg);
    filter: brightness(0.72);
  }

  49% {
    color: transparent;
    transform: rotateX(88deg);
    filter: brightness(0.55);
  }

  50% {
    color: transparent;
    transform: rotateX(-88deg);
    filter: brightness(0.9);
  }

  100% {
    color: #f5f5f5;
    transform: rotateX(0deg);
    filter: brightness(1);
  }
}

@media (max-width: 620px) {
  :root {
    --cell: clamp(27px, min(4.75vh, 9.15vw), 41px);
    --score-cell: clamp(28px, min(4.75vh, 9.45vw), 42px);
    --gap: clamp(3px, 0.45vh, 5px);
  }

  .app-shell {
    width: min(100vw - 10px, 760px);
    gap: 6px;
  }

  .top-bar {
    gap: 7px;
    padding: 7px;
  }

  .brand {
    gap: 7px;
  }

  h1 {
    font-size: clamp(1rem, 3vh, 1.42rem);
  }

  .top-controls {
    gap: 5px;
  }

  .board-head {
    flex-wrap: wrap;
    gap: 4px 8px;
    line-height: 1.15;
  }

  .status-text {
    max-width: 92vw;
  }

  .legend-panel {
    top: 76px;
    right: 8px;
    left: auto;
    width: min(286px, calc(100vw - 16px));
    padding: 13px 12px 12px;
  }

  .legend-list {
    gap: 7px;
  }

  .legend-list li {
    grid-template-columns: 32px 1fr;
    min-height: 36px;
  }

  .legend-icon {
    width: 32px;
    height: 32px;
    font-size: 1.05rem;
  }

  .option-menu {
    right: -46px;
    width: min(284px, calc(100vw - 16px));
  }

  #modeMenu {
    right: 0;
    width: 150px;
  }

  .key-row-mid {
    padding-left: 0;
  }

  .key-row-bottom {
    padding-inline: 0 clamp(58px, 11vw, 82px);
  }
}

@media (max-width: 1180px) and (min-width: 621px) {
  .legend-panel {
    top: 94px;
    right: 14px;
    left: auto;
    width: 220px;
  }
}

@media (max-height: 680px) {
  :root {
    --cell: clamp(24px, 4.35vh, 37px);
    --score-cell: clamp(25px, 4.35vh, 38px);
    --gap: 2px;
  }

  .app-shell {
    padding-block: 5px;
    gap: 5px;
  }

  .top-bar {
    height: clamp(48px, 8vh, 60px);
  }

  .keyboard-shell {
    padding: 6px;
  }

  .key-button {
    height: clamp(29px, 4.9vh, 37px);
  }

  .board-head {
    min-height: 16px;
    font-size: clamp(0.7rem, 1.55vh, 0.86rem);
  }

  .legend-panel {
    top: 76px;
    padding-block: 12px;
  }

  .legend-list {
    gap: 7px;
  }

  .legend-list li {
    min-height: 35px;
  }

  .legend-icon {
    width: 31px;
    height: 31px;
    font-size: 1rem;
  }
}
