/* IBM Plex Mono (SIL Open Font License 1.1), subset files from Fontsource. */

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-cyrillic-ext-400-normal.woff2") format("woff2");
  unicode-range: U+0460-052F,U+1C80-1C8A,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F;
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-cyrillic-400-normal.woff2") format("woff2");
  unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116;
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-cyrillic-ext-700-normal.woff2") format("woff2");
  unicode-range: U+0460-052F,U+1C80-1C8A,U+20B4,U+2DE0-2DFF,U+A640-A69F,U+FE2E-FE2F;
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-cyrillic-700-normal.woff2") format("woff2");
  unicode-range: U+0301,U+0400-045F,U+0490-0491,U+04B0-04B1,U+2116;
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/ibm-plex-mono-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #787c7e;
  --border: #d3d6da;
  --tile-border-filled: #878a8c;
  --key: #d3d6da;
  --key-fg: #1a1a1a;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --tile-fg: #ffffff;
  --toast-bg: #1a1a1a;
  --toast-fg: #ffffff;
  --modal-bg: #ffffff;
  --backdrop: rgba(255, 255, 255, 0.5);
  --gap: 6px;
  --key-height: 58px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --fg: #e6e6e6;
    --muted: #818384;
    --border: #3a3a3c;
    --tile-border-filled: #565758;
    --key: #818384;
    --key-fg: #ffffff;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --toast-bg: #e6e6e6;
    --toast-fg: #121213;
    --modal-bg: #121213;
    --backdrop: rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  -webkit-text-size-adjust: 100%;
}

#game {
  height: 100%;
  height: 100dvh;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  position: relative;
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.2;
}

#board-container {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  padding: 10px 16px;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  grid-gap: 5px;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-gap: 5px;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  -webkit-user-select: none;
}

.tile.filled {
  border-color: var(--tile-border-filled);
  animation: pop 0.1s;
}

.tile.correct,
.tile.present,
.tile.absent {
  border-color: transparent;
  color: var(--tile-fg);
}

.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); }
.tile.absent  { background: var(--absent); }

@keyframes pop {
  from { transform: scale(0.8); }
  40%  { transform: scale(1.1); }
  to   { transform: scale(1); }
}

.row.shake {
  animation: shake 0.5s;
}

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  max-width: calc(100% - 32px);
  padding: 12px 16px;
  border-radius: 6px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  pointer-events: none;
}

.toast p {
  margin: 0;
}

button:focus-visible {
  outline: 2px solid var(--muted);
  outline-offset: 2px;
}

.icon-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: none;
  color: var(--fg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

header .icon-button {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--backdrop);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  padding: 24px 16px 20px;
  border-radius: 8px;
  background: var(--modal-bg);
  color: var(--fg);
  box-shadow: 0 4px 23px rgba(0, 0, 0, 0.2);
  animation: slide-in 0.2s ease-out;
}

@keyframes slide-in {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
}

.result {
  margin: 4px 40px 16px 0;
  font-weight: 700;
  line-height: 1.4;
}

.modal-card h2,
.modal-card h3 {
  margin: 0 0 10px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.stat-row {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.stat {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-value {
  font-size: 2.2rem;
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  line-height: 1.2;
}

.distribution {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0 8px;
  margin-bottom: 20px;
}

.dist-row {
  display: flex;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.dist-label {
  width: 1.2em;
  flex: 0 0 auto;
}

.dist-bar {
  min-width: 7%;
  padding: 2px 8px;
  background: var(--absent);
  color: #fff;
  text-align: right;
}

.dist-bar.today {
  background: var(--correct);
}

.modal-footer {
  display: flex;
  align-items: center;
}

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

.countdown {
  flex: 1 1 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-right: 12px;
  border-right: 1px solid var(--fg);
}

.countdown-value {
  font-size: 1.8rem;
  font-variant-numeric: tabular-nums;
}

.share-button {
  flex: 1 1 50%;
  margin-left: 12px;
  height: 48px;
  border: none;
  border-radius: 4px;
  background: var(--correct);
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
}

.keyboard {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 8px 8px;
  user-select: none;
  -webkit-user-select: none;
}

.key-row {
  --unit: calc((100% - 11 * var(--gap)) / 12);
  display: flex;
  justify-content: center;
  gap: var(--gap);
  touch-action: manipulation;
}

.key {
  flex: 0 0 var(--unit);
  height: var(--key-height);
  padding: 0;
  border: none;
  border-radius: 4px;
  background: var(--key);
  color: var(--key-fg);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.key.wide {
  flex-basis: calc(var(--unit) * 1.5 + var(--gap) * 0.5);
  font-size: 1.1rem;
}

.key.enter {
  font-size: 0.75rem;
  letter-spacing: 0.02em;
}

.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent  { background: var(--absent);  color: #fff; }

@media (max-width: 420px) {
  :root {
    --gap: 4px;
    --key-height: 50px;
  }
  .key {
    font-size: 0.95rem;
  }
  .key.enter {
    font-size: 0.6rem;
    letter-spacing: 0;
  }
}

@media (max-height: 640px) {
  :root {
    --key-height: 44px;
  }
  header {
    height: 44px;
  }
  h1 {
    font-size: 1.4rem;
  }
}
