:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #667085;
  --line: #d9e2ec;
  --surface: #f8fafc;
  --panel: #ffffff;
  --accent: #1769ff;
  --accent-pressed: #0f53cc;
  --danger: #ba1a1a;
  --shadow: 0 18px 50px rgb(15 23 42 / 18%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--surface);
  color: var(--ink);
}

body {
  min-width: 320px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  touch-action: manipulation;
}

button {
  border: 0;
  border-radius: 8px;
  color: inherit;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: grid;
  grid-template-rows: minmax(36px, 6svh) minmax(0, 1fr) auto auto;
  height: 100svh;
  margin: 0 auto;
  max-width: 760px;
  background: var(--panel);
}

.resolver {
  display: grid;
  align-items: center;
  min-height: 36px;
  padding: max(6px, env(safe-area-inset-top)) 12px 6px;
  border-bottom: 1px solid var(--line);
}

.resolved-name {
  min-height: 24px;
  overflow: hidden;
  color: var(--ink);
  font-size: 18px;
  font-weight: 750;
  letter-spacing: 0;
  line-height: 1.1;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resolved-name.muted {
  color: var(--muted);
  font-weight: 650;
}

.flag-stage {
  position: relative;
  display: grid;
  align-items: center;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  background:
    repeating-linear-gradient(90deg, #32854a 0 11%, #2f7c45 11% 22%);
  background-color: #2f7c45;
}

.flag-image {
  display: block;
  width: 100%;
  max-height: 100%;
  filter: drop-shadow(0 18px 22px rgb(0 0 0 / 34%)) drop-shadow(0 4px 5px rgb(0 0 0 / 28%));
  object-fit: contain;
  opacity: 0;
  transition: opacity 140ms ease;
}

.flag-image.is-loaded {
  opacity: 1;
}

.hint-badge {
  position: absolute;
  inset: 0;
  display: grid;
  align-items: center;
  justify-items: center;
  pointer-events: none;
  color: #ffffff;
  font-size: 112px;
  font-weight: 900;
  letter-spacing: 0;
  opacity: 0;
  text-shadow: 0 4px 20px rgb(0 0 0 / 52%), 0 0 1px rgb(0 0 0 / 90%);
  transform: scale(0.96);
  transition: opacity 120ms ease, transform 120ms ease;
}

.hint-badge.is-visible {
  opacity: 1;
  transform: scale(1);
}

.celebration-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.controls {
  display: grid;
  grid-template-columns: minmax(70px, 1fr) auto minmax(140px, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}

.right-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  justify-self: end;
  width: min(190px, 100%);
}

.control-button,
.score-button,
.overlay-actions button,
.key {
  min-height: 44px;
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: 0 1px 1px rgb(15 23 42 / 8%);
  font-weight: 750;
}

.control-button:active,
.score-button:active,
.overlay-actions button:active,
.key:active {
  transform: translateY(1px);
}

.score-button {
  min-width: 82px;
  padding: 0 14px;
  background: #101828;
  color: #ffffff;
  font-size: 18px;
}

.keyboard {
  display: none;
  gap: 7px;
  padding: 8px 8px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #dbe3ed;
  user-select: none;
}

.key-row {
  display: grid;
  gap: 6px;
}

.key-row:nth-child(1) {
  grid-template-columns: repeat(10, minmax(0, 1fr));
}

.key-row:nth-child(2) {
  grid-template-columns: repeat(9, minmax(0, 1fr));
  padding: 0 4.5%;
}

.key-row:nth-child(3) {
  grid-template-columns: 1.35fr repeat(7, minmax(0, 1fr)) 1.35fr;
}

.key-row:nth-child(4) {
  grid-template-columns: 1.25fr 3fr 1.25fr;
}

.key {
  display: grid;
  place-items: center;
  height: clamp(42px, 6.1svh, 58px);
  min-width: 0;
  padding: 0 4px;
  background: #ffffff;
  color: #111827;
  font-size: 18px;
}

.key.wide {
  font-size: 14px;
}

.key.enter {
  background: #eef2f7;
  color: #5f6b7a;
}

.key.enter.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.key.enter.is-active:active {
  background: var(--accent-pressed);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgb(8 13 24 / 70%);
}

.overlay[hidden] {
  display: none;
}

.overlay-panel {
  width: min(430px, 100%);
  padding: 22px;
  border: 1px solid rgb(255 255 255 / 28%);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.overlay-panel h1 {
  margin: 0 0 18px;
  color: var(--danger);
  font-size: 48px;
  letter-spacing: 0;
  line-height: 1;
  text-align: center;
}

#resetTitle {
  color: var(--ink);
  font-size: 34px;
}

.overlay-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.overlay-actions button {
  min-height: 54px;
  padding: 0 12px;
  background: #ffffff;
}

.overlay-actions button:last-child {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

@media (pointer: coarse) {
  .keyboard {
    display: grid;
  }
}

@media (max-width: 420px) {
  .hint-badge {
    font-size: 92px;
  }

  .key {
    font-size: 16px;
  }

  .key.wide {
    font-size: 13px;
  }

  .overlay-panel h1 {
    font-size: 40px;
  }

  #resetTitle {
    font-size: 30px;
  }
}

@media (min-width: 821px) and (pointer: fine) {
  .app {
    grid-template-rows: 44px minmax(0, 1fr) auto;
    height: min(100svh, 920px);
    border-right: 1px solid var(--line);
    border-left: 1px solid var(--line);
  }

  .flag-stage {
    min-height: 420px;
  }
}

@media (orientation: landscape) and (pointer: coarse) {
  body::before {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 24px;
    background: #ffffff;
    color: var(--ink);
    content: "Rotate to portrait";
    font-size: 24px;
    font-weight: 800;
    text-align: center;
  }
}
