/* ===== Design tokens ===== */
:root {
  /* Brand */
  --cardinal:        #8c1515;
  --cardinal-dark:   #5f0a0a;
  --cardinal-light:  #b03030;

  /* Backgrounds */
  --bg:              #f0e9de;
  --bg-card:         #faf6f1;
  --bg-key:          #e2d8cc;
  --bg-key-hover:    #d4c9bb;

  /* Tile states */
  --correct:         #2d7a4f;   /* Stanford green — not Wordle green */
  --present:         #c97b2a;   /* warm amber */
  --absent:          #5a5e6d;   /* cool slate */

  /* Text */
  --text:            #1e1b18;
  --text-light:      #6b6560;
  --text-white:      #ffffff;

  /* UI */
  --radius-tile:     8px;
  --radius-key:      10px;
  --radius-card:     14px;
  --shadow-card:     0 4px 28px rgba(0,0,0,0.10);
  --shadow-tile-in:  inset 0 0 0 2px;  /* used with color */
  --transition:      0.18s ease;

  --font-sans:       'Helvetica Neue', Arial, sans-serif;
  --font-serif:      Georgia, 'Times New Roman', serif;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  /* Subtle warm linen texture via CSS */
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 39px,
      rgba(0,0,0,0.025) 39px,
      rgba(0,0,0,0.025) 40px
    );
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ===== Header ===== */
header {
  width: 100%;
  background: linear-gradient(135deg, var(--cardinal) 0%, var(--cardinal-dark) 100%);
  color: var(--text-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}

.header-left {
  flex: 1;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  gap: 2px;
}

.header-right {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
header h1 {
  font-family: var(--font-serif);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-white);
}
.header-sub {
  font-size: 0.58rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.65);
  font-weight: 400;
}

.header-logo {
  height: 2rem;
  width: auto;
  vertical-align: middle;
}


.icon-btn {
  background: none;
  border: none;
  color: var(--text-white);
  font-size: 1.25rem;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); }

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: max-content;
  max-width: 90vw;
}
.toast {
  background: var(--text);
  color: var(--text-white);
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  animation: toastAnim 1.8s cubic-bezier(.4,0,.2,1) forwards;
  white-space: nowrap;
}
@keyframes toastAnim {
  0%   { opacity: 0; transform: translateY(-10px) scale(0.95); }
  12%  { opacity: 1; transform: translateY(0)     scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-4px); }
}

/* ===== Main layout ===== */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 8px 14px;
  width: 100%;
  max-width: 520px;
  gap: 18px;
}

/* ===== Board card ===== */
#board-container {
  display: flex;
  align-items: center;
  justify-content: center;
}
#board-card {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 7px;
  width: min(310px, 82vw);
}
.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

/* ===== Tiles ===== */
.tile {
  aspect-ratio: 1;
  border-radius: var(--radius-tile);
  background: var(--bg);
  box-shadow: var(--shadow-tile-in) #cdc4b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.35rem, 5vw, 1.85rem);
  font-weight: 800;
  font-family: var(--font-serif);
  text-transform: uppercase;
  color: var(--text);
  user-select: none;
  transition: box-shadow var(--transition);
  position: relative;
}
/* Filled but not yet submitted */
.tile[data-letter] {
  background: var(--bg-card);
  box-shadow: var(--shadow-tile-in) #9a8e83, 0 2px 6px rgba(0,0,0,0.08);
}

/* Pop animation when a letter is typed */
.tile.pop { animation: pop 0.12s ease; }
@keyframes pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.14); }
  100% { transform: scale(1); }
}

/* Shake on invalid word */
.row.shake { animation: shake 0.48s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  18%       { transform: translateX(-7px); }
  36%       { transform: translateX(7px); }
  54%       { transform: translateX(-4px); }
  72%       { transform: translateX(4px); }
}

/* Bounce on win */
.tile.bounce { animation: bounce 0.55s cubic-bezier(.4,0,.2,1) forwards; }
@keyframes bounce {
  0%   { transform: translateY(0); }
  38%  { transform: translateY(-22px); }
  68%  { transform: translateY(-8px); }
  100% { transform: translateY(0); }
}

/* Flip reveal */
.tile.flip { animation: flip 0.52s ease forwards; }
@keyframes flip {
  0%   { transform: rotateX(0deg); }
  49%  { transform: rotateX(90deg); }
  50%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

/* Revealed states */
.tile.correct {
  background: var(--correct);
  box-shadow: none;
  color: var(--text-white);
}
.tile.present {
  background: var(--present);
  box-shadow: none;
  color: var(--text-white);
}
.tile.absent {
  background: var(--absent);
  box-shadow: none;
  color: var(--text-white);
}

/* ===== Keyboard ===== */
#keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  max-width: 490px;
  padding: 0 2px;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}
.key {
  height: 58px;
  min-width: clamp(26px, 8vw, 34px);
  flex: 1;
  max-width: 44px;
  border: none;
  border-radius: var(--radius-key);
  background: var(--bg-key);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  text-transform: uppercase;
  transition: background var(--transition), color var(--transition), transform 0.08s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 rgba(0,0,0,0.12);
  -webkit-tap-highlight-color: transparent;
}
.key:hover  { background: var(--bg-key-hover); }
.key:active { transform: translateY(1px); box-shadow: none; }
.key-wide {
  min-width: clamp(44px, 14vw, 56px);
  max-width: 68px;
  font-size: 0.7rem;
}
.key-spacer { flex: 0.45; max-width: 20px; }

/* Keyboard state colours */
.key.correct { background: var(--correct); color: var(--text-white); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }
.key.present { background: var(--present); color: var(--text-white); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }
.key.absent  { background: var(--absent);  color: var(--text-white); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }

/* ===== Modals ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(30,27,24,0.5);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-card);
  padding: 0;
  max-width: 400px;
  width: 100%;
  position: relative;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 48px rgba(0,0,0,0.22);
}

/* Cardinal accent bar at top of every modal */
.modal-header {
  background: linear-gradient(135deg, var(--cardinal) 0%, var(--cardinal-dark) 100%);
  padding: 16px 20px 14px;
  position: relative;
  flex-shrink: 0;
}
.modal-header h2 {
  color: var(--text-white);
  font-family: var(--font-serif);
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  text-align: center;
}
.modal-close {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.18);
  border: none;
  color: var(--text-white);
  font-size: 1.1rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background var(--transition);
}
.modal-close:hover { background: rgba(255,255,255,0.28); }

.modal-body {
  padding: 20px 22px 22px;
  overflow-y: auto;
  flex: 1;
}
.modal-body p, .modal-body li {
  font-size: 0.88rem;
  line-height: 1.55;
  margin-bottom: 8px;
  color: var(--text);
}
.modal-body ul { padding-left: 18px; margin-bottom: 10px; }
.modal-body h3 {
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 16px 0 10px;
  color: var(--text-light);
}
hr { border: none; border-top: 1px solid #ddd4c8; margin: 14px 0; }

/* Help examples */
.help-examples { margin: 10px 0 6px; }
.example-row { display: flex; gap: 6px; margin: 8px 0 4px; }
.example-tile {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  box-shadow: var(--shadow-tile-in) #cdc4b8;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  font-weight: 800;
  font-family: var(--font-serif);
  text-transform: uppercase;
  background: var(--bg);
}
.example-tile.correct { background: var(--correct); box-shadow: none; color: var(--text-white); }
.example-tile.present { background: var(--present); box-shadow: none; color: var(--text-white); }
.example-tile.absent  { background: var(--absent);  box-shadow: none; color: var(--text-white); }


/* ===== Share modal ===== */
.share-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
  padding: 28px 22px 26px;
}

#share-result-line {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
#share-result-line .result-sub {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-light);
  margin-top: 4px;
}
#share-result-line .result-answer {
  display: block;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-light);
  margin-top: 2px;
}

#share-emoji-grid {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.share-row {
  display: flex;
  gap: 5px;
}
.share-cell {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  background: var(--absent);
}
.share-cell.correct { background: var(--correct); }
.share-cell.present { background: var(--present); }


#btn-share {
  background: linear-gradient(135deg, var(--cardinal) 0%, var(--cardinal-dark) 100%);
  color: var(--text-white);
  border: none;
  border-radius: 24px;
  padding: 13px 40px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  width: 100%;
  transition: filter var(--transition), transform 0.1s;
}
#btn-share:hover  { filter: brightness(1.1); }
#btn-share:active { transform: scale(0.97); }
#btn-share.copied {
  background: linear-gradient(135deg, var(--correct), #3d9b65);
}

.hidden { display: none !important; }

/* ===== Footer ===== */
footer {
  font-size: 0.5rem;
  color: var(--text-light);
  letter-spacing: 0.01em;
  padding: 10px 14px 14px 0;
  opacity: 0.6;
  width: 100%;
  text-align: right;
}

/* ===== Responsive ===== */
@media (max-height: 660px) {
  header { height: 48px; }
  header h1 { font-size: 1.3rem; }
  .header-sub { display: none; }
  main { padding: 12px 8px 10px; gap: 12px; }
  .key { height: 48px; }
  #board-card { padding: 12px; }
}
@media (max-width: 360px) {
  .key { font-size: 0.68rem; }
  #board-card { padding: 10px; }
  #board { gap: 5px; }
  .row { gap: 5px; }
}
