:root{
  --bg: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --border: #e2e8f0;
  --panel: #f8fafc;

  --btn: #0f172a;
  --btnText: #ffffff;
  --btnSecondary: #f1f5f9;
  --btnSecondaryText: #0f172a;

  /* NYT-ish colours (by eye) */
  --nytBlue: #A9CBEA;
  --nytYellow: #F9DF6D;
  --nytGreen: #A0C35A;

  --blueTint: var(--nytBlue);
  --amber: var(--nytYellow);
  --green: var(--nytGreen);

  /* iOS safe-area helpers */
  --safeTop: env(safe-area-inset-top);

  /* Topbar */
  --topbarBase: 56px;

  /* Tile sizing */
  --tile: 132px;
  --tileGap: 12px;
  --tileRadius: 14px;

  /* Text sizing */
  --titleSize: 13px;
  --valueSize: 12px;

  /* Always keep internal breathing room */
  --tilePad: 12px;
  --badgeSpace: 40px;
}

*{ box-sizing: border-box; }

html, body{
  margin: 0;
  padding: 0;
}

body{
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

/* iOS tap ergonomics */
button,
.icon-btn,
.menu-item{
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Header */
.topbar{
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safeTop);
  height: calc(var(--topbarBase) + var(--safeTop));

  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.left-actions{
  display: flex;
  gap: 4px;             /* slightly closer */
  padding-left: 12px;
}

.right-actions{
  width: 64px;          /* balances the centre logo */
}

.icon-btn{
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active{
  opacity: 0.6;
}

/* Both icons render at the same size */
.icon-img{
  width: 22px;
  height: 22px;
  display: block;
}

.icon-fallback{
  font-size: 18px;
  line-height: 1;
}

.brand{
  display: flex;
  justify-content: center;
  align-items: center;
}

.logo{
  height: 42px;
  width: auto;
  max-width: 100%;
  display: block;
}

.logo-text{
  font-weight: 800;
  font-size: 20px;
}

/* Main layout */
main{
  max-width: 680px;
  margin: 0 auto;
  padding: calc(var(--topbarBase) + 12px + var(--safeTop)) 14px 18px 14px;
}

.meta{
  margin: 0.25rem 0 0.4rem 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.subtitle{
  margin: 0 0 0.75rem 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.message{
  margin: 0 0 0.75rem 0;
  color: var(--text);
  font-size: 14px;
  min-height: 18px;
}

.row{
  display: flex;
  gap: 10px;
  margin: 12px 0;
}

/* Controls row should match the 2-tile grid width on mobile */
#controlsRow{
  width: calc((var(--tile) * 2) + var(--tileGap));
  margin-left: auto;
  margin-right: auto;
  justify-content: center;
}


/* Make Undo/Clear/Share the same width as a tile */
#undo, #clear, #share{
  width: var(--tile);
}


/* Buttons */
button{
  width: 100%;
  padding: 12px;
  font-size: 15px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
}

button:disabled{
  opacity: 0.55;
  cursor: default;
}

button.secondary{
  background: var(--btnSecondary);
  color: var(--btnSecondaryText);
  border-color: var(--border);
}

/* Share row centred at bottom */
.share-row{
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

#share.share{
  width: auto;
  padding: 12px 18px;
  background: var(--blueTint);
  color: #000;
  border: 1px solid var(--border);
  border-radius: 14px;
}

/* ===== GRID LAYOUT ===== */
.event-buttons{
  margin: 12px auto 0 auto;

  display: grid;
  grid-template-columns: repeat(3, var(--tile));
  gap: var(--tileGap);

  justify-content: center;
  align-content: start;
}

/* Switch to 2 columns on smaller screens */
@media (max-width: 520px){
  .event-buttons{
    grid-template-columns: repeat(2, var(--tile));
  }
}

/* Event tiles (square) */
.event-btn{
  position: relative;

  transition: transform 220ms ease, background-color 160ms ease;
  will-change: transform;

  background: var(--blueTint);
  border: none;
  border-radius: var(--tileRadius);

  width: var(--tile);
  aspect-ratio: 1 / 1;

  padding: var(--tilePad);
  padding-bottom: calc(var(--badgeSpace) + 2px);

  color: #000;

  display: flex;
  align-items: center;
  justify-content: center;

  text-align: center;

  overflow: hidden;
}

/* Darken selected tile */
.event-btn.selected::after{
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(0,0,0,0.14);
  pointer-events: none;
}

/* Text wrapper */
.event-left{
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;

  align-items: center;
  justify-content: center;
  text-align: center;
}

/* Title text */
.event-title{
  font-weight: 800;
  line-height: 1.15;
  color: #000;

  font-size: var(--titleSize);

  white-space: normal;

  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;

  text-wrap: balance;
}

/* Value reveal */
.event-value{
  margin-top: 6px;
  font-size: var(--valueSize);
  color: rgba(0, 0, 0, 0.72);
  font-weight: 400;

  white-space: normal;

  word-break: normal;
  overflow-wrap: normal;
  hyphens: none;

  text-wrap: balance;
}

/* tiles should not visually “grey out” */
.event-btn:disabled{
  opacity: 1;
  cursor: default;
}

/* Choice badge */
.choice-badge{
  position: absolute;
  right: 10px;
  bottom: 10px;

  width: 30px;
  height: 30px;
  border-radius: 999px;

  display: inline-flex;
  align-items: center;
  justify-content: center;

  font-weight: 800;
  font-size: 13px;
  color: #000;

  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(15, 23, 42, 0.12);

  line-height: 1;
  padding: 0;
  text-align: center;

  z-index: 2;
}

/* Correct-position badge styling */
.choice-badge.badge-correct{
  color: #9ca3af;
  border-color: rgba(15, 23, 42, 0.12);
  background: rgba(255,255,255,0.82);
}

/* Feedback fills */
.event-btn.fb-blue{ background: var(--blueTint) !important; }
.event-btn.fb-yellow{ background: var(--amber) !important; }
.event-btn.fb-green{ background: var(--green) !important; }


/* Final reveal */
.event-btn.final-reveal{
  background: var(--green);
}

/* Dropdown menu (matches your HTML: #menuDropdown.menu-dropdown) */
.menu-dropdown{
  position: fixed;
  top: calc(var(--topbarBase) + var(--safeTop));
  left: 12px;
  z-index: 2000;
  width: 180px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.15);
  padding: 6px;
}

.menu-item{
  display: block;
  padding: 10px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  font-size: 14px;
}

.menu-item:hover{
  background: var(--panel);
}

/* Modal */
.modal[hidden]{ display: none; }

.modal{
  position: fixed;
  inset: 0;
  z-index: 3000;
}

.modal-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
}

.modal-card{
  position: relative;
  z-index: 3001;
  width: min(560px, calc(100% - 28px));
  margin: calc(var(--topbarBase) + 18px + var(--safeTop)) auto 0 auto;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}

.modal-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.modal-header h2{
  margin: 0;
  font-size: 16px;
}

.close-btn{
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #ffffff;
  cursor: pointer;
  font-size: 18px;
}

.modal-body{
  padding: 12px 12px 14px 12px;
  color: var(--text);
  font-size: 14px;
}

/* Dev toggle */
.dev-panel{
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.dev-title{
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.toggle{
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.toggle input{
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-ui{
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
  position: relative;
  flex: 0 0 auto;
}

.toggle-ui::after{
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--border);
  transition: transform 150ms ease;
}

.toggle input:checked + .toggle-ui{
  background: #0f172a;
  border-color: #0f172a;
}

.toggle input:checked + .toggle-ui::after{
  transform: translateX(18px);
  border-color: #0f172a;
}

.toggle-text{
  font-size: 14px;
  color: var(--text);
}

/* Footer build line */
.buildline{
  margin: 22px 0 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* Archive */
.archive-note{
  margin: -0.4rem 0 0.9rem 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
}

.archive-list{
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.archive-link{
  display: block;
  text-decoration: none;
  font-weight: 800;
  font-size: 14px;
  color: #000;
  padding: 10px 12px;
  border-radius: 12px;
}

.archive-link:hover{
  background: var(--panel);
}
