
#game4096 * { box-sizing: border-box; }
#game4096 {
  margin: 0;
  background: #101722;
  color: #edf2fa;
  font-family: system-ui, -apple-system, "Segoe UI", "Yu Gothic", sans-serif;
  line-height: 1.5;
}
#game4096 .game-content { width: min(470px, calc(100% - 24px)); margin: 24px auto; }
#game4096 header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#game4096 h1 { font-size: 42px; line-height: 1; margin: 0; color: #f2ce62; }
#game4096 .scores { display: flex; gap: 8px; }
#game4096 .score {
  position: relative;
  background: #202c3d;
  border-radius: 10px;
  padding: 8px 12px;
  text-align: center;
  min-width: 76px;
  font-variant-numeric: tabular-nums;
}
#game4096 .score span { display: block; font-size: 12px; color: #bdcada; }
#game4096 .score strong { font-size: 20px; overflow-wrap: anywhere; }
#game4096 #gain {
  position: absolute;
  right: 0;
  top: 100%;
  color: #f2ce62;
  font-weight: 800;
  white-space: nowrap;
  z-index: 3;
  font-size: 16px;
}
#game4096 button {
  font: inherit;
  font-weight: 700;
  min-height: 44px;
  border: 1px solid #52647c;
  border-radius: 9px;
  background: #293a50;
  color: #f5f8ff;
  padding: 8px 16px;
  cursor: pointer;
}
#game4096 button:hover { background: #374c66; }
#game4096 button:disabled { opacity: .45; cursor: default; }
#game4096 :focus-visible { outline: 3px solid #f2ce62; outline-offset: 4px; }
#game4096 .toolbar { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin: 16px 0 10px; }
#game4096 .board {
  position: relative;
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
  background: #202c3d;
  padding: 9px;
  border-radius: 14px;
  touch-action: none;
  user-select: none;
}
#game4096 .cell {
  aspect-ratio: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #2c394c;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
#game4096 .cell[data-value="2"] { background: #dae2eb; color: #263348; }
#game4096 .cell[data-value="4"] { background: #ebdfbd; color: #3a321f; }
#game4096 .cell[data-value="8"] { background: #edaa60; color: #281b0d; }
#game4096 .cell[data-value="16"] { background: #ef8750; color: #28170e; }
#game4096 .cell[data-value="32"] { background: #e56b59; color: #26110e; }
#game4096 .cell[data-value="64"] { background: #db4d48; color: #fff; }
#game4096 .cell.high { background: #e8c04c; color: #28200b; }
#game4096 .cell[data-value="128"] { background: #f2db8b; color: #302711; }
#game4096 .cell[data-value="256"] { background: #eac55d; color: #302609; }
#game4096 .cell[data-value="512"] { background: #d5aa35; color: #241b06; }
#game4096 .cell[data-value="1024"] { background: #b98419; color: #fff; }
#game4096 .cell[data-value="2048"] { background: #805408; color: #fff; }
#game4096 .cell[data-value="4096"] { background: #386c52; color: #fff; }
#game4096 .ghost { position: absolute; margin: 0; z-index: 2; pointer-events: none; }
#game4096 .board-wrap { position: relative; }
#game4096 .visual-notice {
  height: 1.5em;
  margin: 6px 0;
  font-size: 14px;
  line-height: 1.5;
}
#game4096 .overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  border-radius: 14px;
  background: #101722df;
}
#game4096 .overlay[hidden] { display: none; }
#game4096 .overlay-panel { text-align: center; max-width: 100%; }
#game4096 #message { display: block; font-size: 24px; font-weight: 800; margin-bottom: 18px; }
#game4096 .overlay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
#game4096 button.primary { background: #f2ce62; border-color: #f2ce62; color: #29200a; }
#game4096 button.primary:hover { background: #ffe08a; }
#game4096 .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
#game4096 .controls {
  display: grid;
  grid-template-columns: repeat(3, 58px);
  gap: 7px;
  justify-content: center;
  margin: 12px 0;
}
#game4096 .controls button { padding: 7px; font-size: 22px; }
#game4096 .up { grid-column: 2; }
#game4096 .left { grid-column: 1; }
#game4096 .help { color: #bdcada; font-size: 14px; margin: 16px 0; }
#game4096 .save-note { font-size: 13px; color: #e5cb82; min-height: 1.5em; }
#game4096 dialog {
  max-width: min(390px, calc(100% - 32px));
  background: #202c3d;
  color: #edf2fa;
  border: 1px solid #52647c;
  border-radius: 14px;
  padding: 22px;
}
#game4096 dialog::backdrop { background: #000a; }
#game4096 dialog h2 { margin-top: 0; font-size: 20px; }
#game4096 .dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 360px) {
  #game4096 .game-content { margin-top: 0; }
  #game4096 .score { padding: 6px 8px; min-width: 66px; }
  #game4096 h1 { font-size: 36px; }
  #game4096 .board { gap: 6px; padding: 7px; }
}
    
.game4096-page{max-width:1120px;margin:20px auto;padding:0 16px;color:#263332;font-family:system-ui,"Yu Gothic",sans-serif}.game4096-page h1{font-size:28px}.game4096-page .game-notes{max-width:740px;margin:24px auto;line-height:1.8}
#game4096{position:relative;margin:auto;border-radius:16px;overflow:hidden;max-width:100%;background:#101722;color:#edf2fa;line-height:1.5}
#game4096 .game-content{width:470px;height:720px;margin:0;padding:18px;transform-origin:top left;position:relative}
#game4096 .board{height:434px;aspect-ratio:1;box-sizing:border-box} #game4096 .toolbar{margin:10px 0} #game4096 .controls{margin:6px 0} #game4096 .visual-notice{margin:2px 0} #game4096 .save-note{margin:2px 0;font-size:12px} #game4096 .game-content>header{height:62px}
#game4096 .menu-overlay{position:absolute;inset:0;z-index:8;background:#101722ed;display:flex;align-items:center;justify-content:center;padding:24px}
#game4096 .menu-overlay[hidden],#game4096 [hidden]{display:none!important} #game4096 .menu-panel{width:100%;max-height:100%;overflow:auto;text-align:center} #game4096 .menu-panel h2{color:#f2ce62;font-size:30px;margin:0 0 18px} #game4096 .menu-panel p{text-align:left} #game4096 .menu-panel button{margin:5px} #game4096 .menu-actions{display:flex;flex-direction:column;max-width:280px;margin:auto} #game4096 .sound-row{display:flex;align-items:center;justify-content:center;gap:12px;margin:16px 0} #game4096 input[type=range]{width:190px} #game4096 .controls{grid-template-columns:repeat(4,64px)} #game4096 .up,#game4096 .left{grid-column:auto} #game4096 .overlay-panel{max-height:100%;overflow:auto} #game4096 .board-wrap .overlay{padding:12px}

#game4096 #confirm-new{z-index:10} #game4096 #help-menu,#game4096 #settings-menu{z-index:9}

#game4096 .board-title{font-size:42px;line-height:1;margin:0;color:#f2ce62;font-weight:700} /* The game uses a square frame. UI controls retain their CSS pixel size. */
#game4096{width: min(800px,100%);aspect-ratio:1;max-width:100%;margin:0 auto;container-type:size}
#game4096 .game-content{position:relative;width:100%;height:100%;margin:0;padding:0;transform:none!important}
#game4096 .board-wrap{position:absolute;left:10px;top:10px;width:var(--board-size);height:var(--board-size)}
#game4096 .board{width:100%;height:100%;padding:7px;gap:5px;border-radius:12px}
#game4096 .game-content>header{position:absolute;left:calc(var(--board-size) + 20px);right:10px;top:10px;height:52px;display:block}
#game4096 .board-title{display:none}
#game4096 .scores{width:100%;gap:5px}
#game4096 .score{padding:3px;min-width:0;flex:1;border-radius:7px}
#game4096 .score span{font-size:14px;line-height:1.4}
#game4096 .score strong{font-size:18px;line-height:1.4}
#game4096 .toolbar{position:absolute;left:10px;right:10px;bottom:10px;height:44px;margin:0;display:flex;flex-wrap:nowrap;gap:6px}
#game4096 .toolbar button{flex:1;min-width:0;min-height:44px;padding:4px;font-size:14px}
#game4096 .controls{position:absolute;left:calc(var(--board-size) + 20px);right:10px;top:70px;display:grid;grid-template-columns:repeat(2,44px);grid-auto-rows:44px;gap:6px;margin:0}
#game4096 .controls button{height:44px;min-height:44px;padding:0;font-size:24px}
#game4096 .save-note{position:absolute;left:calc(var(--board-size) + 20px);right:10px;top:172px;bottom:64px;overflow:auto;margin:0;font-size:14px;line-height:1.35}
#game4096 .visual-notice{position:absolute;left:15px;top:15px;max-width:calc(var(--board-size) - 10px);height:auto;background:#101722e8;border-radius:5px;margin:0;z-index:3;font-size:14px;pointer-events:none}
#game4096 .visual-notice:empty{display:none}
#game4096 .menu-overlay{padding:12px}
#game4096 .menu-panel{max-width:560px;max-height:100%;font-size:14px;line-height:1.4}
#game4096 .menu-panel h2{font-size:24px;line-height:1.3;margin:0 0 10px}
#game4096 .menu-panel p{margin:8px 0}
#game4096 .menu-panel button{font-size:14px;min-height:44px;margin:0;padding:6px 10px}
#game4096 .menu-actions{display:grid;grid-template-columns:1fr 1fr;gap:8px;max-width:340px}
#game4096 .sound-row{margin:8px 0;gap:8px;min-height:44px}
#game4096 input[type=range]{width:160px;min-height:44px}
#game4096 input[type=checkbox]{width:22px;height:22px}
#game4096 .overlay-panel{width:100%;max-height:100%;overflow:auto;font-size:14px}
#game4096 #message{font-size:24px;margin-bottom:10px}
#game4096 .overlay-actions{gap:6px}
#game4096 .overlay-actions button{font-size:14px;min-height:44px;padding:6px 10px}
/* Results use the full game frame so phone controls stay together. */
#game4096 #status{inset:0;border-radius:16px}
#game4096 #status .overlay-panel{max-width:560px;margin:auto}

/* Description panels follow oshifuda; related links follow colormix. */
.game4096-page{box-sizing:border-box;width:min(1120px,calc(100% - 48px));max-width:none;margin:0 auto 64px;padding:0;color:#2e3131;font-size:16px;line-height:1.8}
.game4096-page > .breadcrumb { padding-top: 8px; color: #667572; font-size: .875rem; line-height: 20px; }
.game4096-page > .breadcrumb ol { display: flex; flex-wrap: wrap; gap: 2px 6px; margin: 0; padding: 0; list-style: none; }
.game4096-page > .breadcrumb li { display: flex; align-items: baseline; gap: 6px; }
.game4096-page > .breadcrumb a { color: #26755b; text-underline-offset: 3px; }
.game4096-page .game-intro{padding:4px 0 32px}
.game4096-page .game-intro h1{margin:0 0 16px;font-size:clamp(28px,4vw,42px);line-height:1.3}
.game4096-page .game-intro p{margin:0;color:#6e7473}
.game4096-page .game-toolbar{padding-right:110px;margin-bottom:12px;min-height:44px;display:flex;align-items:center}
.game4096-page .game-toolbar p{margin:0;color:#6e7473;font-size:14px;line-height:1.6}
.game4096-page .game-toolbar strong{color:#347a68;margin-right:8px}
.game4096-page .game-fullscreen-open,.game4096-page .game-fullscreen-close{min-height:44px}
.game4096-page .description-section{padding:64px 0 12px}
.game4096-page .description-section h2,.game4096-page .info-section h2{margin:0 0 22px;font-size:32px;line-height:1.3}
.game4096-page .description-panel{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:30px;padding:28px 30px;border:1px solid #e4e9df;border-left:5px solid #62ad98;border-radius:8px;background:#fff}
.game4096-page .description-block+.description-block{padding-left:30px;border-left:1px solid #e4e9df}
.game4096-page .description-block h3{margin:0 0 12px;font-size:20px;line-height:1.4}
.game4096-page .guide-list{display:grid;gap:0;margin:0}
.game4096-page .guide-list>div{display:grid;grid-template-columns:115px minmax(0,1fr);gap:12px;padding:9px 0;border-bottom:1px solid #edf0eb}
.game4096-page .guide-list>div:last-child{border:0}
.game4096-page .guide-list dt{color:#347a68;font-weight:800}
.game4096-page .guide-list dd{margin:0;color:#545d5b}
.game4096-page .info-section{padding:32px 0}
.game4096-page .info-section p{margin:0}
.game4096-page .info-section a{color:#347a68;text-underline-offset:3px}
.game4096-page .game-notes{max-width:none}
.game4096-page .game-shell.is-game-fullscreen .game-toolbar{display:none}
@media(max-width:760px){
.game4096-page{width:calc(100% - 32px)}
.game4096-page > .breadcrumb{padding-top:4px}
.game4096-page .game-intro{padding:0 0 24px}
.game4096-page .description-section{padding-top:48px}
.game4096-page .description-section h2,.game4096-page .info-section h2{font-size:27px}
.game4096-page .description-panel{grid-template-columns:1fr;padding:22px 20px;gap:24px}
.game4096-page .description-block+.description-block{padding:24px 0 0;border-left:0;border-top:1px solid #e4e9df}
.game4096-page .guide-list>div{grid-template-columns:1fr;gap:2px;padding:10px 0}
}

.game4096-site{margin:0;background:#fffefd;color:#2e3131;font-family:system-ui,-apple-system,"Segoe UI","Yu Gothic",Meiryo,sans-serif}
.game4096-page .game-toolbar{position:absolute;top:10px;left:0;right:110px;padding:0;margin:0;height:44px}

.game4096-page .game-shell{box-sizing:border-box}

/* The score row and board share a left edge and width. */
#game4096 .board-wrap { left: 6px; top: 26px; }
#game4096 .game-content > header {
  left: 6px;
  right: auto;
  top: 4px;
  width: var(--board-size);
  height: 19px;
}
#game4096 .score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
  height: 19px;
  padding: 1px 6px;
}
#game4096 .score span { font-size: 11px; line-height: 1.1; }
#game4096 .score strong { font-size: 14px; line-height: 1.1; }

#game4096 .controls {
  left: auto;
  right: 2px;
  top: auto;
  bottom: 2px;
  width: 136px;
  height: 136px;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 2px;
}
#game4096 .controls [data-direction="up"] { grid-column: 2; grid-row: 1; }
#game4096 .controls [data-direction="left"] { grid-column: 1; grid-row: 2; }
#game4096 .controls [data-direction="right"] { grid-column: 3; grid-row: 2; }
#game4096 .controls [data-direction="down"] { grid-column: 2; grid-row: 3; }

#game4096 .toolbar { left: 6px; right: 144px; bottom: 6px; }
#game4096 .toolbar button { padding: 4px 1px; flex: 1 1 auto; font-size: 14px; }
#game4096 .save-note {
  left: 6px;
  right: 144px;
  top: calc(var(--board-size) + 30px);
  bottom: 54px;
  line-height: 1.3;
}
#game4096 .visual-notice { left: 11px; top: 31px; }
#game4096[data-layout="compact"] .toolbar button { font-size: 12px; }
#game4096[data-layout="compact"] .save-note { font-size: 12px; }
#game4096[data-layout="compact"] .cell { border-radius: 5px; }
#game4096[data-layout="compact"] .board { gap: 2px; padding: 4px; }

@container (max-width: 288px) {
  #game4096 .toolbar { gap: 3px; }
  #game4096 .toolbar button { font-size: 11px; }
}
@media (max-width: 480px) {
  .game4096-page .game-shell { width: calc(100% + 32px); margin-left: -16px; }
  .game4096-page .game-toolbar { left: 16px; }
  .game4096-page .game-shell.is-game-fullscreen {
    padding-left: max(4px, env(safe-area-inset-left)) !important;
    padding-right: max(4px, env(safe-area-inset-right)) !important;
  }
}

@media (max-width: 760px) and (orientation: portrait),
       (min-width: 761px) and (min-height: 480px) {
  #game4096 {
    --board-size: calc(100cqw - 12px);
    --below-board-height: 160px;
  }
  #game4096 .controls {
    left: 0;
    right: 0;
    top: calc(var(--board-size) + 34px);
    bottom: auto;
    margin-inline: auto;
  }
  #game4096 .toolbar {
    left: auto;
    right: calc(50% + 74px);
    top: calc(var(--board-size) + 34px);
    bottom: auto;
    width: calc(50% - 80px);
    max-width: 136px;
    height: 136px;
    flex-direction: column;
    gap: 2px;
  }
  #game4096 .save-note {
    left: calc(50% + 74px);
    right: 6px;
    top: calc(var(--board-size) + 34px);
    bottom: 2px;
  }
}

#game4096 .cell {
  font-size: clamp(5px, calc((100cqw - 34px) * 0.29 / var(--tile-digits)), 36px);
}
#game4096[data-layout="compact"] .cell {
  font-size: clamp(5px, calc((100cqw - 16px) * 0.29 / var(--tile-digits)), 32px);
}

/* In wide fullscreen layouts, the close button sits beside the square. */
@media (min-width: 680px) and (min-aspect-ratio: 7/4) {
  .game4096-page .game-shell.is-game-fullscreen {
    padding-top: max(4px, env(safe-area-inset-top)) !important;
    padding-bottom: max(4px, env(safe-area-inset-bottom)) !important;
  }
}

#game4096[data-busy="true"]::after {
  content: '開始を準備しています…';
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  background: #101722f2;
  color: #edf2fa;
  font-size: 16px;
  font-weight: 700;
}
