:root {
  font-family: Arial, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color: #252525;
  background: #fff;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .65; }
button:focus-visible, select:focus-visible { outline: 3px solid #183bca; outline-offset: 3px; }
[hidden] { display: none !important; }
.game-page { width: min(100% - 40px, 990px); margin: 35px auto; }
.page-header { display: flex; align-items: baseline; justify-content: space-between; padding: 0 10px 16px; }
h1 { margin: 0; font-size: 21px; font-weight: 700; }
.header-options { display: flex; align-items: center; gap: 12px; }
.header-options > span { font-size: 12px; color: #6d6d6d; }
#mode-select { padding: 7px 8px; border: 1px solid #b4d5b9; border-radius: 6px; background: #f2fbef; color: #166c1f; font-size: 12px; cursor: pointer; }

.game-machine {
  position: relative;
  overflow: clip;
  padding: 36px 37px 0;
  border-radius: 28px;
  background: linear-gradient(#15cd77 0, #00c86b 11%, #00c86b 93%, #00b65a 100%);
  box-shadow: 1px 3px 2px #0003;
}
.playfield {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 47px;
  padding: 26px 11px 25px 25px;
  border: 2px solid #afd88f;
  border-radius: 3px;
  background-color: #d9f7c7;
  background-image: linear-gradient(#fff9 1.5px, transparent 1.5px), linear-gradient(90deg, #fff9 1.5px, transparent 1.5px);
  background-size: 12px 12px;
  box-shadow: inset 2px 2px 4px #1c591a30;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}
.board-wrap { position: relative; z-index: 1; min-width: 0; container-type: inline-size; touch-action: none; user-select: none; -webkit-user-select: none; }
.board { display: grid; grid-template-rows: repeat(10, minmax(0, 1fr)); aspect-ratio: 17 / 10; touch-action: none; }
.board-row { display: grid; grid-template-columns: repeat(17, minmax(0, 1fr)); min-height: 0; }
.apple-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  touch-action: none;
  color: #fff;
  cursor: crosshair;
}
.apple-visual {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  pointer-events: none;
  transform-origin: center;
}
.apple-image { position: absolute; width: 93%; height: 93%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.apple-number {
  position: relative;
  z-index: 1;
  font-size: clamp(8px, 2.4cqw, 21px);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  padding-top: 16%;
  text-shadow: 0 1px 1px #8b241b35;
  pointer-events: none;
}
.apple-cell.empty > * { visibility: hidden; }
.apple-cell.selected .apple-image, .harvest-effect .apple-image {
  filter: drop-shadow(1px 0 0 #ffff66) drop-shadow(-1px 0 0 #ffff66) drop-shadow(0 1px 0 #ffff66) drop-shadow(0 -1px 0 #ffff66);
}
.apple-cell:focus-visible { z-index: 3; outline-offset: -2px; }
.selection { position: absolute; z-index: 3; border: 1px solid #2299cc; background: rgb(255 153 0 / 30%); pointer-events: none; }
.selection.valid { background: rgb(255 0 0 / 50%); }
.score-rail { display: flex; flex-direction: column; align-items: center; padding-left: 12px; }
.score-label { color: #329624; font-size: 10px; margin: -9px 0 3px; }
.score { color: #0aaf00; font-size: 25px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.time-track { position: relative; width: 12px; flex: 1; margin: 16px 0 8px; background: #c0e7a2; overflow: hidden; }
.time-fill { position: absolute; bottom: 0; width: 100%; height: 100%; background: #0dde00; transition: height .1s linear; }
.timer { color: #389421; font-size: 12px; font-variant-numeric: tabular-nums; }
.score-rail.urgent .time-fill { background: #f34527; }
.score-rail.urgent .timer { color: #d02e19; }
.game-controls { height: 47px; display: flex; align-items: center; justify-content: space-between; padding: 0 9px; color: white; }
.reset-button { padding: 2px 8px 3px; border: 1px solid #b5ffd1; color: #fff; background: transparent; font-size: 13px; }
.reset-button:hover { background: #ffffff20; }
.sound-control { display: flex; align-items: center; gap: 4px; font-size: 12px; cursor: pointer; }
.sound-control input { accent-color: #fff; width: 13px; height: 13px; margin: 0; }
.overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: #e7fbd5b0; }
.overlay-content { text-align: center; }
.start-button, .again-button {
  min-width: 138px;
  border: 2px solid #fff;
  padding: 12px 27px;
  background: #04ba54;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 2px 0 #288538;
}
.start-button:hover, .again-button:hover { background: #00a84b; }
.start-button, .again-button, .reset-button { transition: background-color .15s, transform .12s; }
.start-button:active, .again-button:active, .reset-button:active { transform: translateY(1px) scale(.97); }
.overlay:not([hidden]) .overlay-content { animation: result-appear .22s ease-out; }
.overlay-content h2 { color: #166c1f; font-size: 27px; margin: 0 0 12px; }
.result-score { font-size: 52px; font-variant-numeric: tabular-nums; color: #0b9d14; margin: 0 0 18px; }
.result-score small { font-size: 18px; padding-left: 5px; }
.again-button { font-size: 16px; }
.asset-error { max-width: 270px; font-size: 14px; color: #7d2517; line-height: 1.6; }
.effects { position: absolute; inset: 0; pointer-events: none; z-index: 4; overflow: visible; }
.harvest-effect { inset: auto; will-change: transform; }
.point-effect { position: absolute; z-index: 1; color: #14884e; font-size: clamp(12px, 2cqw, 17px); font-weight: 400; text-shadow: 0 1px 2px white; animation: points .65s ease-out forwards; }
.point-effect small { font-size: inherit; white-space: nowrap; }
@keyframes points { 0%, 65% { opacity: 1; } from { transform: translate(-50%, 0); } to { transform: translate(-50%, -20px); opacity: 0; } }
@keyframes result-appear { from { transform: translateY(5px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes feedback-fade { 0%, 65% { opacity: 1; } 100% { opacity: 0; } }
.instructions { margin: 17px 12px 0; color: #333; font-size: 13px; line-height: 1.6; }
.mode-note { margin: 4px 12px 0; color: #467447; font-size: 12px; line-height: 1.6; }
.mobile-note { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 700px) {
  .game-page { width: calc(100% - 16px); margin: 14px auto; }
  .page-header { padding: 0 6px 10px; }
  h1 { font-size: 18px; }
  .header-options { gap: 7px; }
  .header-options > span { font-size: 10px; }
  #mode-select { padding: 6px; font-size: 11px; }
  .game-machine { padding: 18px 15px 0; border-radius: 17px; }
  .playfield { grid-template-columns: minmax(0, 1fr) 28px; padding: 12px 7px 12px 10px; background-size: 8px 8px; }
  .score-rail { padding-left: 7px; }
  .score-label { font-size: 8px; margin-top: -5px; }
  .score { font-size: 17px; }
  .time-track { width: 7px; margin: 8px 0 5px; }
  .timer { font-size: 9px; }
  .game-controls { height: 37px; padding-inline: 2px; }
  .reset-button, .sound-control { font-size: 11px; }
  .selection { border-width: 1px; }
  .start-button { min-width: 95px; padding: 8px 18px; font-size: 17px; }
  .overlay-content h2 { font-size: 18px; margin-bottom: 5px; }
  .result-score { font-size: 34px; margin-bottom: 8px; }
  .result-score small { font-size: 13px; }
  .again-button { min-width: 100px; font-size: 13px; padding: 7px 16px; }
  .instructions { margin: 12px 6px 0; font-size: 11px; }
  .mode-note { margin: 4px 6px 0; font-size: 10px; }
  .mobile-note { display: block; margin: 5px 6px; color: #777; font-size: 10px; }
}

@media (orientation: landscape) and (max-height: 550px) {
  .game-page { width: min(calc(100% - 24px), calc((100svh - 166px) * 1.7 + 95px)); margin: 8px auto; }
  .page-header { padding-bottom: 5px; }
  h1 { font-size: 15px; }
  .game-machine { padding: 13px 15px 0; border-radius: 17px; }
  .playfield { padding: 10px 7px 10px 10px; grid-template-columns: minmax(0, 1fr) 28px; }
  .score-rail { padding-left: 7px; }
  .score { font-size: 18px; }
  .score-label { font-size: 8px; margin-top: -4px; }
  .time-track { width: 8px; margin: 6px 0; }
  .game-controls { height: 32px; }
  .instructions { margin-top: 6px; font-size: 10px; }
  .mode-note { margin-top: 2px; font-size: 10px; }
  .mobile-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
  .point-effect { transform: translateX(-50%); animation: feedback-fade .65s ease-out forwards !important; }
}
