/* Classic Tetris for the XP desktop. All selectors are scoped to .tt-app
   so the game cannot affect the surrounding desktop. */

.tt-app {
  --tt-cell: 22px;
  --tt-mini: 12px;
  --tt-menu-h: 26px;
  --tt-ghost: #888;
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #c0c0c0;
  color: #000;
  font: 12px/1.2 Tahoma, "MS Sans Serif", Verdana, Arial, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}
.tt-app:focus-visible { outline: 2px solid #316ac5; outline-offset: -2px; }
.tt-app button { font: inherit; }

/* Menubar ------------------------------------------------------------- */

.tt-menubar {
  position: relative;
  z-index: 20;
  flex: none;
  display: flex;
  align-items: center;
  gap: 1px;
  height: var(--tt-menu-h);
  padding: 0 4px;
  border-bottom: 1px solid #aca899;
  background: #ece9d8;
}

.tt-menu { position: relative; }

.tt-menu-button {
  padding: 2px 7px;
  border: 0;
  background: transparent;
  color: #000;
  cursor: default;
}
.tt-menu-button:hover,
.tt-menu.open > .tt-menu-button { background: #316ac5; color: #fff; }

.tt-menu-list {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 30;
  display: none;
  min-width: 188px;
  padding: 2px;
  border: 1px solid #aca899;
  background: #fff;
  box-shadow: 2px 2px 3px rgba(0, 0, 0, .25);
}
.tt-menu.open > .tt-menu-list { display: block; }

.tt-menu-item {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 23px;
  padding: 3px 20px 3px 22px;
  border: 0;
  background: transparent;
  color: #000;
  text-align: left;
  white-space: nowrap;
  cursor: default;
}
.tt-menu-item:hover,
.tt-menu-item:focus-visible { background: #316ac5; color: #fff; outline: none; }
.tt-check { position: absolute; left: 6px; width: 12px; text-align: center; }
.tt-shortcut { margin-left: auto; padding-left: 22px; color: #696969; }
.tt-menu-item:hover .tt-shortcut,
.tt-menu-item:focus-visible .tt-shortcut { color: #fff; }
.tt-sep { height: 0; margin: 3px 4px; border-top: 1px solid #aca899; }

.tt-pause-button {
  margin-left: auto;
  padding: 2px 8px;
  border: 1px solid #b7c9da;
  border-radius: 3px;
  background: linear-gradient(#fff, #dceaf6);
  color: #163c69;
  font-size: 11px;
  cursor: pointer;
}
.tt-pause-button:hover { border-color: #4788cd; background: #eef7ff; }
.tt-pause-button:active { background: #d5e6f5; }

/* Layout -------------------------------------------------------------- */

.tt-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 8px;
}

@media (min-width: 651px) {
  .tt-main { width: 100%; max-width: 560px; margin-inline: auto; }
}

.tt-side {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 76px;
  min-height: 0;
}

.tt-panel {
  padding: 4px 5px;
  border: 2px solid;
  border-color: #fff #808080 #808080 #fff;
  background: #c0c0c0;
}

.tt-panel-title {
  display: block;
  margin-bottom: 3px;
  color: #4a4a4a;
  font-size: 9px;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.tt-mini {
  display: grid;
  grid-template-columns: repeat(4, var(--tt-mini));
  grid-auto-rows: var(--tt-mini);
  justify-content: center;
  padding: 2px;
  border: 2px solid;
  border-color: #808080 #fff #fff #808080;
  background: #101018;
}

.tt-mini-cell {
  width: var(--tt-mini);
  height: var(--tt-mini);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05);
}
.tt-mini-cell.on { box-shadow: inset 1px 1px 0 rgba(255, 255, 255, .45), inset -1px -1px 0 rgba(0, 0, 0, .35); }

.tt-hold.tt-locked .tt-mini { opacity: .4; }

.tt-queue { display: flex; flex-direction: column; gap: 6px; }

.tt-stats { display: grid; gap: 3px; }
.tt-stat { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.tt-stat span { color: #5a5a5a; font-size: 9px; letter-spacing: .04em; text-transform: uppercase; }
.tt-stat b { font-size: 12px; font-variant-numeric: tabular-nums; }

.tt-playfield {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.tt-board {
  flex: none;
  display: grid;
  grid-template-columns: repeat(10, var(--tt-cell));
  grid-auto-rows: var(--tt-cell);
  padding: 2px;
  border: 3px solid;
  border-color: #808080 #fff #fff #808080;
  background: #101018;
  box-shadow: 0 1px 0 #dfdfdf;
}

.tt-cell {
  width: var(--tt-cell);
  height: var(--tt-cell);
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .045);
}
.tt-cell.filled { box-shadow: inset 2px 2px 0 rgba(255, 255, 255, .45), inset -2px -2px 0 rgba(0, 0, 0, .4); }
.tt-cell.ghost { box-shadow: inset 0 0 0 2px var(--tt-ghost); opacity: .45; }

/* Touch controls ------------------------------------------------------ */

.tt-touch {
  flex: none;
  display: none;
  gap: 8px;
  padding: 6px 8px 8px;
  justify-content: center;
  background: #c0c0c0;
}

.tt-touch button {
  display: grid;
  place-items: center;
  flex: 1 1 0;
  max-width: 74px;
  height: 46px;
  padding: 0;
  border: 2px solid;
  border-color: #fff #808080 #808080 #fff;
  background: #c0c0c0;
  color: #1a1a1a;
  font-size: 16px;
  line-height: 1;
  touch-action: none;
  cursor: pointer;
}
.tt-touch button:active {
  border-color: #808080 #fff #fff #808080;
  background: #b2b2b2;
}

/* Overlay ------------------------------------------------------------- */

.tt-overlay {
  position: absolute;
  z-index: 25;
  top: var(--tt-menu-h);
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(18, 18, 18, .55);
}
.tt-overlay[hidden] { display: none; }

.tt-overlay-panel {
  width: min(320px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 14px 16px 16px;
  border: 2px solid;
  border-color: #fff #808080 #808080 #fff;
  background: #ece9d8;
  color: #17283a;
  text-align: center;
  box-shadow: 3px 3px 10px rgba(0, 0, 0, .35);
}

.tt-overlay-title {
  margin: 0 0 6px;
  color: #173c63;
  font-size: 22px;
  letter-spacing: .16em;
}

.tt-overlay[data-kind="over"] .tt-overlay-title { color: #9b1c14; }

.tt-copy { margin: 8px 0 0; color: #3c4c5c; font-size: 12px; }
.tt-final { margin: 10px 0 0; color: #173c63; font-size: 20px; font-weight: bold; letter-spacing: .06em; }

.tt-keys {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  color: #4a5c70;
  font-size: 11px;
  text-align: left;
}
.tt-keys kbd {
  display: inline-block;
  min-width: 16px;
  padding: 1px 4px;
  border: 1px solid #a9bccd;
  border-radius: 2px;
  background: #fff;
  color: #1b3a57;
  font: inherit;
  text-align: center;
}

.tt-primary {
  margin-top: 14px;
  min-width: 104px;
  padding: 5px 16px;
  border: 1px solid #4b91d3;
  border-radius: 3px;
  background: linear-gradient(#fff, #c5ddf3);
  color: #163c69;
  font-weight: bold;
  cursor: pointer;
}
.tt-primary:hover { border-color: #1c5e9b; background: linear-gradient(#fff, #d9ecfb); }
.tt-primary:focus-visible { outline: 2px solid #316ac5; outline-offset: 2px; }

/* Dialogs ------------------------------------------------------------- */

.tt-modal {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, .2);
}
.tt-modal[hidden] { display: none; }

.tt-dialog {
  display: flex;
  flex-direction: column;
  width: min(340px, 100%);
  max-height: 100%;
  overflow: hidden;
  border: 1px solid #0a3c9a;
  border-radius: 4px;
  background: #ece9d8;
  box-shadow: 2px 4px 12px rgba(0, 0, 0, .35);
}

.tt-dialog-head {
  display: flex;
  align-items: center;
  padding: 4px 6px 4px 9px;
  background: linear-gradient(180deg, #3a91ed 0%, #176ed3 35%, #0960c7 72%, #287cdf 100%);
  color: #fff;
  font-weight: bold;
  text-shadow: 1px 1px 2px #123c83;
}
.tt-dialog-title { flex: 1; }
.tt-dialog-x {
  width: 22px;
  height: 20px;
  padding: 0;
  border: 1px solid #fff;
  border-radius: 3px;
  background: linear-gradient(#f49a80, #dc351e 55%, #ad180b);
  color: #fff;
  font-weight: bold;
  cursor: pointer;
}

.tt-dialog-body { padding: 12px; overflow: auto; color: #172b3e; }
.tt-dialog-body p { margin: 0 0 8px; }
.tt-dialog-body p:last-child { margin-bottom: 0; }
.tt-help { margin: 0 0 8px; padding-left: 18px; }
.tt-help li { margin: 3px 0; }
.tt-help kbd {
  display: inline-block;
  min-width: 16px;
  padding: 1px 4px;
  border: 1px solid #a9bccd;
  border-radius: 2px;
  background: #fff;
  font: 11px/1.2 Tahoma, Verdana, sans-serif;
}
.tt-hint { color: #53677b; font-size: 11px; }

.tt-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid #c1d4e8;
  background: linear-gradient(#eaf3fb, #cbddef);
}
.tt-dialog-actions button {
  min-width: 72px;
  padding: 4px 12px;
  border: 1px solid #abc0d6;
  border-radius: 3px;
  background: linear-gradient(#fff, #d9e5f0);
  color: #213e59;
  cursor: pointer;
}
.tt-dialog-actions button:hover { border-color: #4b91d3; }
.tt-dialog-actions button.primary {
  border-color: #4b91d3;
  background: linear-gradient(#fff, #c5ddf3);
  font-weight: bold;
}

/* Screen-reader only -------------------------------------------------- */

.tt-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Loading and error states -------------------------------------------- */

.tt-loading,
.tt-error {
  margin: 0;
  padding: 24px 12px;
  color: #172b3e;
  text-align: center;
}
.tetris-body > .tt-loading,
.tetris-body > .tt-error { margin: auto; }
.tt-error { color: #b00000; max-width: 460px; }

/* Small screens ------------------------------------------------------- */

@media (max-width: 650px) {
  .tt-app { --tt-menu-h: 30px; font-size: 13px; }
  .tt-menubar { padding: 0 3px; }
  .tt-menu-button { padding: 5px 9px; }
  .tt-pause-button { padding: 4px 8px; font-size: 10px; }

  .tt-main {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 4px 6px;
    padding: 6px;
  }
  .tt-left { grid-area: 1 / 1 / 2 / 3; flex-direction: row; align-items: stretch; width: auto; gap: 6px; }
  .tt-right { grid-area: 1 / 3 / 2 / 4; width: auto; }
  .tt-playfield { grid-area: 2 / 1 / 3 / 4; }

  .tt-panel { padding: 3px 5px; }
  .tt-panel-title { margin-bottom: 2px; font-size: 8px; }
  .tt-queue { flex-direction: row; gap: 4px; }
  .tt-queue .tt-mini { padding: 1px; border-width: 1px; }
  .tt-stats { display: flex; flex-direction: column; justify-content: center; gap: 0; }
  .tt-stat span { font-size: 8px; }
  .tt-stat b { font-size: 11px; }
  .tt-best { display: none; }

  .tt-touch { display: flex; padding-bottom: 10px; }
  .tt-overlay-panel { padding: 12px; }
  .tt-overlay-title { font-size: 19px; }
  .tt-keys { font-size: 10px; gap: 3px 8px; }
}

@media (max-width: 390px) {
  .tt-touch { gap: 6px; }
  .tt-touch button { height: 42px; }
  .tt-keys { grid-template-columns: 1fr; }
}
