:root {
  --c-gray-100: #fbf8f2;
  --c-gray-200: #fcfdfe;
  --c-gray-300: #e9ebec;
  --c-gray-400: #e3e4ea;
  --c-gray-500: #5f5f5f;
  --c-gray-900: #1d1d1d;
  --c-blue-300: #a8dee2;
  --c-blue-500: #2ab3c0;
  --c-green-500: #80b895;
  --c-green-300: #bad5ca;
  --c-red-500: #ea605e;
  --c-yellow-300: #f8e0b1;
  --c-yellow-500: #f9bc73;
  --rotation: -3deg;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--c-gray-400);
  color: var(--c-gray-900);
  font: 14px/1.5 'Press Start 2P', monospace, sans-serif;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 5vw;
}
.wrap {
  width: 95vw;
  max-width: 600px;
  padding: 2rem;
  background: #fff;
  border-radius: 25px;
  box-shadow: 0 0 0 10px var(--c-gray-300), 0 0 0 11px var(--c-gray-200);
  display: flex;
  flex-direction: column;
}
h1 {
  font-weight: 400;
  font-size: clamp(16px, 4vw, 20px);
  margin: 0 0 0.5rem;
  text-align: center;
}
h1 small {
  display: block;
  font-size: 12px;
  color: var(--c-gray-500);
  margin-top: 4px;
}
.grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.card {
  background: #fff;
  border: 2px solid var(--c-gray-900);
  border-radius: 20px;
  padding: 1rem;
  position: relative;
  box-shadow: 0 0 0 2px var(--c-gray-900), 0 8px 10px -4px rgba(0,0,0,0.2);
}
.card::after {
  content: '';
  position: absolute;
  z-index: -1;
  width: 95%;
  height: 100%;
  bottom: -9px;
  left: calc(50% - 47.5%);
  border-radius: 20px;
  border: 2px solid var(--c-gray-900);
  background: var(--c-yellow-300);
}
.card h2 {
  font-size: 12px;
  margin: 0 0 0.75rem;
  color: var(--c-gray-500);
  font-weight: 400;
  text-transform: uppercase;
}
.row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0.5rem 0;
}
.row label {
  padding-right: 10px;
}
select, button, input[type="text"] {
  width: 100%;
  max-width: 100%;
  min-height: 36px;
  min-width: 0; /* Prevent overflow in grid/flex */
  background: var(--c-gray-100);
  color: var(--c-gray-900);
  border: 2px solid var(--c-gray-900);
  border-radius: 15px;
  padding: 10px 30px 10px 10px;
  font: inherit;
  font-size: 12px;
  line-height: 1.5;
  box-sizing: border-box;
  transition: 0.15s ease;
}
select {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg fill='black' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select:focus, button:focus, input[type="text"]:focus {
  background: var(--c-yellow-300);
  outline: none;
}
select:hover, button:hover, input[type="text"]:focus {
  background: var(--c-yellow-500);
}
#badInk,
#jewColor,
#jewJap {
  width: 150px;
}
#inked {
  width: 100%; /* Explicitly ensure full width */
}
input[type="radio"] {
  accent-color: var(--c-blue-500);
}
.checkline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.checkline label {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--c-gray-100);
  border: 2px solid var(--c-gray-900);
  padding: 8px;
  border-radius: 15px;
  font-size: 12px;
}
.pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  background: var(--c-gray-100);
  border: 2px dashed var(--c-gray-900);
  padding: 8px 10px;
  border-radius: 999px;
  color: var(--c-gray-500);
  font-size: 12px;
}
.muted { color: var(--c-gray-500); }
.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.btns button {
  flex: 1;
  min-width: 120px;
  padding: 8px;
  font-size: 10px;
}
.tip {
  font-size: 10px;
  color: var(--c-gray-500);
  margin-top: 8px;
}
.hidden { display: none !important; }
.warn { color: var(--c-red-500); }
.bad { color: var(--c-red-500); }
.good { color: var(--c-green-500); }
hr {
  border: none;
  border-top: 2px solid var(--c-gray-900);
  margin: 10px 0;
}
.bignote {
  font-size: 10px;
  color: var(--c-gray-500);
}
#debugToggle {
  align-self: center;
  margin-top: 1rem;
  background: var(--c-blue-300);
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 10px;
}
#debugToggle:hover {
  background: var(--c-blue-500);
}
.debug-badge {
  font-size: 8px;
  color: var(--c-gray-900);
  background: var(--c-yellow-500);
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: 6px;
}
.dbggrid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kbd {
  font-family: 'Press Start 2P', monospace;
  background: var(--c-gray-100);
  border: 2px solid var(--c-gray-900);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 10px;
}
#popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 2px solid var(--c-gray-900);
  padding: 1rem;
  border-radius: 20px;
  color: var(--c-gray-900);
  z-index: 1000;
  min-width: 280px;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 8px 10px -4px rgba(0,0,0,0.2);
}
#popup p {
  margin: 0 0 10px;
  font-size: 12px;
  padding: 0 10px;
}
#receiptCanvas {
  display: block;
  margin: 10px auto;
  border: 2px solid var(--c-gray-900);
  border-radius: 15px;
  background: #fff;
  width: 400px;
  height: 400px;
}
#popup .btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  justify-content: center;
}
#popup button {
  background: var(--c-blue-500);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 10px;
  flex: 1 1 120px;
  min-width: 120px;
  border-radius: 15px;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#popup button:hover {
  background: var(--c-blue-300);
}
.leaderboard {
  max-height: 120px;
  overflow-y: auto;
  font-size: 12px;
  text-align: left;
  margin: 10px;
  padding: 10px;
  background: var(--c-gray-100);
  border: 2px solid var(--c-gray-900);
  border-radius: 15px;
}
.leaderboard div {
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#adPlaceholder {
  background: var(--c-gray-100);
  border: 2px dashed var(--c-gray-900);
  min-height: 90px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--c-gray-500);
  text-align: center;
  margin-top: 10px;
}
@media (min-width: 768px) {
  .wrap { width: min(1100px, 90vw); }
  .grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 1rem; }
  .card:first-child { grid-column: span 8; }
  .card:nth-child(2) { grid-column: span 4; }
  .card:last-child { grid-column: span 12; }
  .row {
    display: grid;
    grid-template-columns: auto 1fr; /* Label takes minimum space, select takes remaining */
    gap: 10px;
    align-items: center;
  }
  .dbggrid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px; }
  .dbggrid > div { grid-column: span 4; }
  h1 { font-size: clamp(18px, 3vw, 24px); }
  h1 small { font-size: 14px; }
  #popup { min-width: 400px; }
  #adPlaceholder { min-height: 250px; }
}