:root {
  --navy: #0b2545;
  --sea: #13a4a4;
  --sand: #f4efe6;
  --coral: #ff6b57;
  --grey: #8a9aad;
  --line: #d7cfc2;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--sand);
  color: var(--navy);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

header {
  width: 100%;
  padding: 10px 12px calc(10px + env(safe-area-inset-top));
  text-align: center;
  background: var(--navy);
  color: var(--sand);
}
h1 { margin: 0; font-size: 22px; letter-spacing: .16em; text-transform: uppercase; }
.how { margin: 4px 0 0; font-size: 13px; opacity: .85; }

main {
  width: 100%;
  max-width: 480px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  gap: 8px;
}

/* Board */
#board { display: grid; gap: 5px; }
.row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.tile {
  width: clamp(46px, 15vw, 60px);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 6px;
  font-size: clamp(22px, 7vw, 30px);
  font-weight: 700;
  text-transform: uppercase;
}
.tile.filled { border-color: var(--grey); }
.tile.g { background: var(--sea); border-color: var(--sea); color: #fff; }
.tile.y { background: var(--coral); border-color: var(--coral); color: #fff; }
.tile.x { background: var(--grey); border-color: var(--grey); color: #fff; }
.row.bad { animation: shake .3s; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

#msg { margin: 0; min-height: 20px; font-size: 14px; font-weight: 600; color: var(--coral); }

/* Keyboard */
#kb { width: 100%; display: flex; flex-direction: column; gap: 6px; padding-bottom: env(safe-area-inset-bottom); }
.krow { display: flex; gap: 5px; justify-content: center; }
.krow button {
  flex: 1;
  min-width: 0;
  height: 54px;
  border: 0;
  border-radius: 6px;
  background: #fff;
  color: var(--navy);
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  text-transform: uppercase;
  cursor: pointer;
}
.krow button.wide { flex: 1.6; font-size: 12px; letter-spacing: .05em; }
.krow button.g { background: var(--sea); color: #fff; }
.krow button.y { background: var(--coral); color: #fff; }
.krow button.x { background: var(--grey); color: #fff; }
.krow button:active { transform: translateY(1px); }
.spacer { flex: .5; }

/* Result sheet */
#sheet {
  position: fixed;
  inset: 0;
  background: rgba(11, 37, 69, .7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#sheet[hidden] { display: none; }
.card {
  position: relative;
  width: 100%;
  max-width: 340px;
  background: var(--sand);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}
.card h2 { margin: 0 0 4px; font-size: 22px; }
.card p { margin: 0 0 12px; font-size: 15px; }
.card p b { color: var(--sea); letter-spacing: .1em; }
#close {
  position: absolute;
  top: 4px; right: 4px;
  width: 44px; height: 44px;
  border: 0; background: none;
  color: var(--navy);
  font-size: 24px; line-height: 1;
  cursor: pointer;
}
#stats { display: flex; justify-content: space-around; margin: 0 0 14px; }
#stats div { flex: 1; }
#stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; opacity: .7; }
#stats dd { margin: 2px 0 0; font-size: 22px; font-weight: 700; }
#dist { margin-bottom: 14px; font-size: 12px; }
.bar { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.bar span:first-child { width: 10px; font-weight: 700; }
.bar i {
  display: block;
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--grey);
  color: #fff;
  font-style: normal;
  text-align: right;
}
.bar i.me { background: var(--sea); }
#share {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--sea);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
#fallback { width: 100%; margin-top: 10px; font-family: inherit; }

footer { padding: 10px 0 calc(14px + env(safe-area-inset-bottom)); font-size: 13px; }
footer a { color: var(--navy); }
