:root {
  --ink: #4a4a4a;
  --red-pencil: #b4382e;
  --blue-pencil: #1f3b9b;
  --graphite: #555555;
  --quiet-ink: #65615a;
  --paper: #fbf9f2;
  --grid: rgba(86, 140, 214, .32);
  --paper-grid: 24px;
  --paper-margin: 36px;
}

html { background: #b6a58a; }
html[data-malzeme="kursunkalem"] body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 320px;
  margin: 0;
  padding: 60px 24px 24px;
  color: var(--ink);
  font: 400 20px/1.4 'Kalam', cursive;
  background: radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, .22), transparent 70%), url('kit/gren.png'), #b6a58a;
  overflow-x: visible;
  user-select: auto;
  -webkit-user-select: auto;
}
::selection { color: var(--ink); background: #ead2b4; }
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button:not(:disabled), select { cursor: pointer; }
select, input { font: inherit; color: inherit; accent-color: var(--red-pencil); }
select:focus-visible, input:focus-visible { outline: 2px dashed var(--red-pencil); outline-offset: 3px; }
button:focus-visible { outline: 2px dashed var(--red-pencil); outline-offset: 3px; }
.notebook { position: relative; width: 100%; max-width: clamp(600px, calc((100svh - 180px) * 1.5), 960px); margin: auto; }
.back-link {
  position: absolute; top: -52px; left: 16px;
  display: inline-flex; align-items: center; min-height: 44px;
  color: var(--graphite); font: 18px/1 'Patrick Hand', cursive;
  text-decoration: none; text-underline-offset: 4px;
}
.back-link:hover { color: var(--blue-pencil); text-decoration: underline; }
.back-link:focus-visible { outline: 2px dashed var(--blue-pencil); outline-offset: 3px; }
.sayfa {
  --kagit-egimi: -.6deg;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 20px 36px 10px 60px;
  background: none;
}
html[data-malzeme="kursunkalem"] .sayfa { box-shadow: none; }
.sayfa::before, .sayfa::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: url('kit/gren.png') #f7f4eb;
}
/* Türk Daması ve Tavla gibi: kâğıt katmanları hafif sola yatar; yazı, tahta ve dokunma katmanı düz kalır. */
.sayfa::before {
  z-index: -3; transform: translate(5px, 4px) rotate(calc(var(--kagit-egimi) + .7deg));
  background-color: #efebdf;
  box-shadow: 16px 28px 40px -6px rgba(58, 36, 16, .44);
}
.sayfa::after {
  z-index: -2; transform: translate(-3px, 7px) rotate(calc(var(--kagit-egimi) - .5deg));
  background-color: #ece6d7;
  box-shadow: 0 1px 2px rgba(40, 24, 10, .25);
}
.paper-surface {
  position: absolute; z-index: -1; inset: 0; pointer-events: none;
  transform: rotate(var(--kagit-egimi));
  background-color: var(--paper);
  background-image:
    linear-gradient(to right, transparent var(--paper-margin), rgba(214, 64, 64, .6) var(--paper-margin), rgba(214, 64, 64, .6) calc(var(--paper-margin) + 1px), transparent calc(var(--paper-margin) + 1px)),
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px),
    url('kit/gren.png');
  background-size: 100% 100%, var(--paper-grid) var(--paper-grid), var(--paper-grid) var(--paper-grid), 256px 256px;
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, .85);
}
/* Üst satır Türk Daması gibi: başlık solda, skor ve sıra tahtanın ortasında. */
.heading { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; column-gap: 24px; }
h1 { grid-column: 1; grid-row: 1; justify-self: start; margin: 8px 0 0; color: var(--ink); font: 400 clamp(40px, 3.3vw, 46px)/1.15 'Kalam', cursive; letter-spacing: -.01em; white-space: nowrap; }
.title-word { padding: 0 .03em .1em 0; }
.turn { grid-column: 2; grid-row: 1; text-align: center; min-width: 0; padding-top: 0; }
.turn-status { display: block; }
.score { display: flex; flex-direction: column; align-items: center; }
.score-label { font-size: 16px; color: var(--quiet-ink); line-height: 1.15; }
.score-line { display: flex; align-items: baseline; justify-content: center; gap: 10px; font-size: 24px; line-height: 1.3; white-space: nowrap; }
.player-name { display: inline-flex; align-items: center; gap: .35em; }
.player-dot { display: inline-flex; width: .52em; height: .6em; }
.player-dot svg { width: 100%; height: 100%; overflow: visible; }
.score-number { font-variant-numeric: tabular-nums; }
.score-dash { color: var(--graphite); }
.turn-title { color: var(--blue-pencil); font-size: 30px; line-height: 1.25; margin: 2px 0 0; }
.turn-instruction { margin: 2px 0 0; color: var(--quiet-ink); font-size: 19px; line-height: 1.45; min-height: 1.45em; text-wrap: balance; }
.pencil-underline { position: relative; display: inline-block; }
.pencil-underline > svg { position: absolute; left: -3%; bottom: -.07em; width: 106%; height: .28em; pointer-events: none; overflow: visible; }
.title-word > svg { bottom: -.06em; height: .2em; }

.board {
  display: grid;
  grid-template-columns: .87fr repeat(6, 1fr) .87fr;
  grid-template-rows: auto auto 10px auto auto;
  column-gap: 12px;
  row-gap: 3px;
  align-items: stretch;
  margin-block: 8px 0;
  width: 100%;
}
.row-label { text-align: center; font-size: 18px; margin: 0 0 8px; }
.row-label-top { grid-row: 1; grid-column: 2 / 8; color: var(--red-pencil); }
.row-label-bottom { grid-row: 5; grid-column: 2 / 8; color: var(--blue-pencil); margin: 6px 0 0; }
.pit-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; grid-column: 2 / 8; min-width: 0; }
.pit-row-top { grid-row: 2; }
.pit-row-bottom { grid-row: 4; }
.pit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: start;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  touch-action: manipulation;
}
.pit-visual { position: relative; width: 100%; aspect-ratio: 1; }
.pit-visual > svg { display: block; width: 100%; height: 100%; overflow: visible; }
.pit-count { font-size: 18px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.pit-row-top .pit-count { color: var(--red-pencil); }
.pit-row-bottom .pit-count { color: var(--blue-pencil); }
.pit[aria-disabled="true"] { cursor: default; }
.pit:not([aria-disabled="true"]) { cursor: var(--kalem-imlec); }
.pit .selection-ring { opacity: 0; }
.pit[aria-pressed="true"] .selection-ring, .pit:focus-visible .selection-ring { opacity: 1; }
.pit:focus-visible { outline-offset: 2px; }
@media (hover: hover) {
  .pit:not([aria-disabled="true"]):hover .well-hover { opacity: .055; }
}
.well-hover { opacity: 0; }
.store { grid-row: 2 / 5; display: flex; flex-direction: column; align-items: center; position: relative; min-width: 0; }
.store-top { grid-column: 1; color: var(--red-pencil); }
.store-bottom { grid-column: 8; color: var(--blue-pencil); }
.store-owner { position: absolute; bottom: calc(100% + 8px); font-size: 20px; line-height: 1.3; white-space: nowrap; }
.store-well { position: relative; flex: 1; width: 100%; min-height: 0; }
.store-well > svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.store-count { position: absolute; bottom: 9%; left: 0; right: 0; text-align: center; color: var(--ink); font-size: 27px; line-height: 1; }
.store-caption { position: absolute; top: calc(100% + 7px); color: var(--ink); font-size: 17px; }

.footer { margin-top: 18px; }
.invitation { margin: 0 0 6px; text-align: center; font-size: 18px; color: var(--graphite); }
/* Alt satır: solda oyun modu (ayarları açar), sağda altı çizili komutlar ve hoparlör. */
.footer-line { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.mode { min-height: 44px; padding: 4px 0; border: 0; background: none; font-size: 17px; color: var(--quiet-ink); text-align: left; white-space: nowrap; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 5px; touch-action: manipulation; }
.mode:hover { color: var(--blue-pencil); }
.invitation:empty { display: none; }
.commands { display: flex; align-items: center; justify-content: flex-end; gap: 6px 22px; }
.word-command { display: inline-flex; align-items: center; justify-content: center; padding: 2px 0; min-height: 44px; min-width: 44px; border: 0; background: none; font-size: 23px; white-space: nowrap; touch-action: manipulation; }
.word-command:disabled { cursor: default; color: var(--blue-pencil); opacity: .72; }
.word-command.undo:disabled { color: var(--quiet-ink); opacity: .65; }
.sound { flex-direction: column; gap: 0; }
.sound svg { display: block; width: 34px; height: 34px; }
.sound-text { font-size: 12px; line-height: 1; color: var(--quiet-ink); }

.no-script { color: var(--red-pencil); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.match-score { margin: 5px 0 0; font-size: 18px; color: var(--graphite); }
.turn-title.upper-turn { color: var(--red-pencil); }
.word-command:not(:disabled):hover, .small-command:hover { color: var(--blue-pencil); }
.animation-note { display: none; justify-content: center; align-items: center; gap: 20px; margin-bottom: 12px; font-size: 18px; }
.animation-note:has(> :not([hidden])) { display: flex; }
.small-command { border: 0; padding: 5px 2px; min-height: 44px; min-width: 44px; background: none; font-size: 18px; text-decoration: underline; text-underline-offset: 4px; }
#carried-stone { position: fixed; top: 0; left: 0; z-index: 5; pointer-events: none; width: 24px; height: 24px; }
#carried-stone svg { display: block; width: 24px; height: 24px; margin: -12px; }
.sound-on path:nth-last-child(-n+2) { visibility: hidden; }
.result-note { text-align: center; margin: 16px auto 0; padding: 12px 0; max-width: 680px; border-block: 1px solid var(--graphite); }
.result-note h2 { color: var(--red-pencil); font-size: 32px; font-weight: 400; margin: 0 0 8px; }
.result-note p { margin: 6px 0; }
.result-note .word-command { text-decoration: underline; text-underline-offset: 5px; }
#set-history { font-size: 18px; }
.paper-note {
  color: var(--ink); font: 400 21px/1.5 'Kalam', cursive;
  box-sizing: border-box; width: min(520px, calc(100% - 24px)); max-height: calc(100dvh - 32px);
  padding: 28px; border: 0; border-radius: 0;
  box-shadow: 16px 28px 40px -6px rgba(58, 36, 16, .44);
  background: url('kit/gren.png'), var(--paper); overflow: auto;
  scrollbar-color: var(--graphite) var(--paper);
}
.paper-note::backdrop { background: rgba(58, 36, 16, .18); }
.paper-note h2 { font: 400 30px/1.3 'Kalam', cursive; margin: 0; }
.paper-note h3 { font-size: 23px; font-weight: 400; margin: 20px 0 8px; }
.paper-note p { margin: 12px 0; }
.note-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.paper-note label { display: flex; flex-direction: column; gap: 4px; margin: 16px 0; }
.paper-note select { width: 100%; min-width: 0; min-height: 44px; padding: 4px 24px 4px 0; background: transparent; border: 0; border-bottom: 1px solid var(--graphite); border-radius: 0; }
.paper-note select:disabled { opacity: .5; cursor: default; }
.paper-note .check-label { flex-direction: row; align-items: center; min-height: 44px; gap: 12px; }
.check-label input { width: 22px; height: 22px; flex: 0 0 22px; }
.note-small { font-size: 17px; color: var(--graphite); }
.primary-command { color: var(--red-pencil); text-decoration: underline; text-underline-offset: 6px; }
.help-note { width: min(660px, calc(100% - 24px)); }
.rules { padding-left: 26px; }
.rules li { padding-left: 4px; margin-block: 10px; }
.tutorial { margin-top: 24px; padding-top: 4px; border-top: 1px solid var(--graphite); }
.example-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin: 8px 0; text-align: center; }
.example-row span { min-height: 38px; display: grid; place-items: center; border: 1px solid var(--graphite); border-radius: 48% 52% 46% 54%; }
.example-row .example-source { border-color: var(--red-pencil); border-width: 2px; color: var(--red-pencil); }
.example-store { font-size: 16px; color: var(--graphite); }
.example-store:last-child { text-align: right; }

@media (min-width: 600px) and (max-width: 1000px) {
  html[data-malzeme="kursunkalem"] body { padding: 52px 16px 16px; }
  .sayfa { padding: 18px 24px 10px 52px; gap: 10px; }
  .turn-instruction { font-size: 17px; }
  .footer { margin-top: 14px; }
  .heading { grid-template-columns: minmax(0, 1fr); row-gap: 4px; }
  h1, .turn { grid-column: 1; grid-row: auto; }
  h1 { margin-top: 0; }
  .score-label { font-size: 14px; }
  .score-line { font-size: 20px; gap: 8px; }
  .turn-title { font-size: 24px; }
  .board, .pit-row { column-gap: 6px; }
  .store-owner { font-size: 18px; }
  .commands { gap: 16px; }
  .footer-line { flex-direction: column-reverse; gap: 0; }
  .mode { padding: 0; font-size: 15px; }
}

@media (max-width: 599px) {
  :root { --paper-grid: 20px; --paper-margin: 22px; }
  html[data-malzeme="kursunkalem"] body { padding: 48px 8px 12px; font-size: 18px; }
  .notebook { max-width: 430px; }
  .sayfa { --kagit-egimi: -.3deg; }
  .sayfa::before { transform: translate(2px, 3px) rotate(calc(var(--kagit-egimi) + .4deg)); }
  .sayfa::after { transform: translate(-1px, 1.5px) rotate(calc(var(--kagit-egimi) - .3deg)); }
  .back-link { left: 10px; }
  .sayfa { padding: 16px 12px 12px 34px; gap: 10px; }
  .heading { grid-template-columns: auto minmax(0, 1fr); gap: 6px 8px; align-items: center; padding-inline: 6px; }
  h1 { margin: 0; font-size: clamp(34px, 9vw, 40px); }
  .turn { display: contents; }
  .turn-status { grid-column: 2; grid-row: 1; display: block; text-align: right; }
  .turn-title { font-size: 22px; line-height: 1.2; margin: 0; }
  .turn-instruction { font-size: 16px; line-height: 1.2; min-height: 0; }
  .score { grid-column: 1 / -1; grid-row: 2; flex-direction: row; justify-content: center; align-items: baseline; gap: 0 6px; }
  .score-label { font-size: 14px; }
  .score-line { font-size: clamp(17px, 5vw, 21px); gap: 6px; }
  .match-score { grid-column: 1 / -1; grid-row: 3; text-align: center; margin: 0; font-size: 16px; }
  .board { grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: 54px auto 8px auto 54px; column-gap: 4px; row-gap: 4px; }
  .row-label { font-size: 16px; line-height: 1.25; margin: 0; align-self: center; text-wrap: balance; }
  .row-label-top { grid-column: 4 / 7; grid-row: 1; padding-left: 4px; }
  .row-label-bottom { grid-column: 1 / 4; grid-row: 5; padding-right: 4px; }
  .pit-row { grid-column: 1 / -1; gap: 4px; }
  .pit-row-top { grid-row: 2; }
  .pit-row-bottom { grid-row: 4; }
  .pit-count { font-size: 17px; line-height: 1.15; }
  .store { height: 54px; justify-self: stretch; padding-top: 18px; padding-bottom: 0; }
  .store-top { grid-column: 1 / 4; grid-row: 1; }
  .store-bottom { grid-column: 4 / 7; grid-row: 5; width: 100%; }
  .store-owner { bottom: auto; top: 0; left: 4px; font-size: 14px; line-height: 18px; }
  .store-caption { top: 0; right: 4px; font-size: 14px; line-height: 18px; }
  .store-count { bottom: 50%; left: auto; right: 9%; transform: translateY(50%); font-size: 20px; }
  .footer { margin-top: 8px; }
  .invitation { font-size: 16px; line-height: 1.3; margin: 0 0 4px; text-wrap: balance; }
  .footer-line { flex-direction: column-reverse; gap: 0; }
  .mode { padding: 0; font-size: 14px; }
  .commands { flex-wrap: wrap; justify-content: center; column-gap: 20px; row-gap: 0; max-width: 340px; }
  .word-command { font-size: 20px; }
  .sound { flex-direction: row; gap: 4px; }
  .sound svg { width: 24px; height: 24px; }
  .sound-text { font-size: 14px; }
  .animation-note { gap: 10px; margin-bottom: 0; font-size: 16px; }
  .paper-note { padding: 18px; font-size: 18px; }
  .paper-note h2 { font-size: 32px; }
  .result-note { margin-inline: 4px; font-size: 18px; }
  .result-note h2 { font-size: 28px; }
}

@media (max-width: 419px) {
  :root { --paper-margin: 11px; }
  html[data-malzeme="kursunkalem"] body { padding-inline: 7px; }
  .sayfa { padding: 14px 8px 12px 18px; }
  .heading { padding-inline: 0; }
  .board, .pit-row { column-gap: 3px; }
}

/* Short, wide windows keep the whole board close to its commands. */
@media (min-width: 600px) and (max-height: 600px) {
  html[data-malzeme="kursunkalem"] body { padding-top: 46px; padding-bottom: 8px; }
  .notebook { max-width: 700px; }
  .back-link { top: -46px; }
  .heading { grid-template-columns: auto minmax(0, 1fr); column-gap: 16px; }
  h1 { grid-row: 1; }
  .turn { grid-column: 2; grid-row: 1; }
  .sayfa { padding: 6px 20px 6px 48px; gap: 8px; }
  .store-owner { font-size: 16px; }
  h1 { font-size: 40px; }
  .score-line { font-size: 18px; }
  .turn-status { display: flex; justify-content: center; align-items: baseline; flex-wrap: wrap; gap: 0 10px; }
  .turn-title { font-size: 22px; }
  .turn-instruction { font-size: 15px; line-height: 1.3; min-height: 0; }
  .board { margin-top: 0; }
  .row-label { font-size: 16px; margin-block: 0; }
  .board { grid-template-rows: auto auto 4px auto auto; }
  .pit-visual { max-width: 46px; }
  .pit-count { font-size: 16px; }
  .footer { margin: 0; }
  .invitation { font-size: 16px; margin-bottom: 0; }
  .score { flex-direction: row; justify-content: center; align-items: baseline; gap: 0 8px; }
  .footer-line { flex-direction: row; flex-wrap: wrap-reverse; justify-content: center; gap: 0 16px; }
  .mode { font-size: 15px; }
  .commands { gap: 12px; }
  .word-command { font-size: 18px; }
  .sound { flex-direction: row; gap: 3px; }
  .sound svg { width: 24px; height: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .pit:focus-visible { outline: 2px solid Highlight; }
  .pit svg path, .store svg path { stroke: CanvasText !important; }
  .pit[aria-pressed="true"] { outline: 3px solid Highlight; }
}

@media print {
  .back-link, .sayfa::before, .sayfa::after { display: none; }
  .paper-note, .paper-surface { box-shadow: none; }
}
