:root{
  --bg: #062b20;
  --panel: #0a3d2d;
  --text: #f0fdf4;
  --muted: #c1ddce;
  --accent: #86efac;
  --btn: #0b5138;
  --btn-hover: #13704b;
  --ring: #86efac99;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body{
  min-height: 100dvh;
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  background: #000;
  color: var(--text);
}

.topbar{
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: calc(12px + var(--safe-top)) 12px 12px;
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  background: linear-gradient(110deg, rgba(4, 45, 32, .96), rgba(10, 81, 56, .92));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(134, 239, 172, .4);
}
.controls{
  display: flex; gap: 8px; flex-wrap: wrap;
}
.btn{
  background: linear-gradient(135deg, #0b5138, #0a3d2d);
  color: var(--text);
  border: 1px solid rgba(134, 239, 172, .42);
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: transform .05s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
  min-width: 80px;
}
.btn.is-active{
  background: linear-gradient(135deg, rgba(74, 222, 128, .42), rgba(20, 83, 45, .82));
  border-color: rgba(187, 247, 208, .95);
}
.btn:hover{ background: linear-gradient(135deg, #13704b, #0b5138); border-color: var(--accent); }
.btn:active{ transform: translateY(1px); }
.btn:focus{ outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn:focus-visible{ box-shadow: 0 0 0 3px var(--ring); }

.status{
  display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  font-size: 14px; color: var(--muted);
}

.main{
  max-width: 980px;
  margin: 20px auto;
  padding: 0 calc(12px + var(--safe-left)) calc(24px + var(--safe-bottom));
  padding-right: calc(12px + var(--safe-right));
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 110px);
}

.version-counter{
  position: fixed;
  z-index: 30;
  left: calc(8px + var(--safe-left));
  bottom: calc(8px + var(--safe-bottom));
  padding: 4px 7px;
  border: 1px solid rgba(134, 239, 172, .24);
  border-radius: 8px;
  background: rgba(4, 45, 32, .4);
  color: rgba(193, 221, 206, .72);
  font-size: 11px;
  line-height: 1;
  letter-spacing: .04em;
  pointer-events: none;
  user-select: none;
}

.current-card{
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(4, 45, 32, .84), rgba(6, 43, 32, .7));
  border: 1px solid rgba(134, 239, 172, .45);
  border-radius: 16px;
  overflow: hidden;
  padding: 0;
}
.card-frame{
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: min(100%, 78vh);
  max-width: 100%;
  height: 100%;
  line-height: 0;
  padding: 0;
}

.card-frame img{
  display: block;
  width: 100%;
  height: auto;
  max-height: min(68vh, 78vw);
  object-fit: contain;
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.5));
  animation: pop .18s ease-out;
}

.placeholder{
  color: var(--muted);
  font-size: 14px;
}

.dealt-section{
  margin-top: 18px;
  margin-bottom: 0;
}
.dealt-section h2{
  font-size: 16px;
  color: var(--muted);
  font-weight: 500;
  margin: 8px 0 10px;
}
.dealt-strip{
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  align-items: end;
}
.dealt-strip .card-frame{
  display: inline-block;
}

.dealt-strip img{
  height: 88px;
  width: auto;
  border-radius: 8px;
  border: 1px solid rgba(134, 239, 172, .45);
  background: var(--panel);
}

@keyframes pop{
  from{ transform: scale(.98); opacity: .9; }
  to{ transform: scale(1); opacity: 1; }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  body {
    background-position: center top;
    background-attachment: scroll;
  }
  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .controls {
    width: 100%;
    justify-content: space-between;
  }
  .btn {
    flex: 1;
    min-width: auto;
    padding: 10px 8px;
    font-size: 12px;
  }
  .status {
    width: 100%;
    justify-content: space-between;
    font-size: 13px;
  }
  .main {
    min-height: calc(100dvh - 130px);
  }
  .current-card {
    min-height: 42vh;
    padding: 0;
  }
  .card-frame {
    width: min(100%, 90vw);
  }
  .card-frame img {
    max-height: min(60vh, 90vw);
  }
  .dealt-strip img {
    height: 72px;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 8px;
  }
  .btn {
    padding: 8px 6px;
    font-size: 11px;
  }
  .controls {
    gap: 6px;
  }
  .main {
    margin: 12px auto;
    padding: 0 8px 16px;
    min-height: calc(100dvh - 120px);
  }
  .current-card {
    min-height: 38vh;
    border-radius: 12px;
    padding: 0;
  }
  .card-frame {
    width: min(100%, 92vw);
  }
  .card-frame img {
    max-height: min(54vh, 92vw);
  }
  .dealt-section h2 {
    font-size: 14px;
  }
  .dealt-strip {
    gap: 6px;
  }
  .dealt-strip img {
    height: 60px;
    border-radius: 4px;
  }
}

/* Fold outer display: use width/orientation, not height, because standalone iOS may reserve system UI space. */
@media (min-width: 450px) and (max-width: 500px) and (orientation: portrait) {
  html,
  body {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
  body {
    display: flex;
    flex-direction: column;
  }
  .topbar {
    position: relative;
    flex: 0 0 auto;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 0;
    padding-top: calc(8px + var(--safe-top));
    padding-right: calc(8px + var(--safe-right));
    backdrop-filter: none;
  }
  .controls {
    position: fixed;
    z-index: 20;
    left: auto;
    right: calc(8px + var(--safe-right));
    bottom: calc(12px + var(--safe-bottom));
    width: 100px;
    padding: 8px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    border: 1px solid rgba(134, 239, 172, .45);
    border-radius: 16px;
    background: rgba(4, 45, 32, .94);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
    backdrop-filter: blur(10px);
  }
  .status {
    width: auto;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: nowrap;
    gap: 16px;
    padding: 4px 2px 8px;
  }
  .status span {
    white-space: nowrap;
  }
  .btn {
    flex: 0 0 auto;
    width: 100%;
    min-height: 44px;
    padding: 6px 4px;
    font-size: 11px;
  }
  .main {
    width: auto;
    max-width: none;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin: 12px calc(116px + var(--safe-right)) 12px 8px;
    padding: 0 0 calc(8px + var(--safe-bottom));
  }
  .current-card {
    flex: 1 1 0;
    min-height: 0;
  }
  .dealt-section {
    display: flex;
    flex: 0 0 104px;
    flex-direction: column;
    min-height: 0;
    margin: 8px 0 0;
    overflow: hidden;
  }
  .dealt-section h2 {
    flex: 0 0 auto;
    margin: 0 0 6px;
  }
  .dealt-strip {
    display: flex;
    flex: 1 1 0;
    min-height: 0;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 4px;
    align-items: flex-end;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .dealt-strip .card-frame {
    display: inline-block;
    flex: 0 0 auto;
    width: auto;
    height: auto;
  }
  .dealt-strip img {
    display: block;
    height: 60px;
    width: auto;
  }
}

/* Fold inner landscape: ignore small standalone viewport-height differences from status/system bars. */
@media (min-width: 800px) and (max-width: 1100px) and (orientation: landscape) and (min-aspect-ratio: 27/20) and (max-aspect-ratio: 8/5) {
  html,
  body {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
  body {
    display: flex;
    flex-direction: column;
  }
  .topbar {
    position: relative;
    flex: 0 0 auto;
  }
  .main {
    max-width: 1400px;
    width: 100%;
    flex: 1 1 auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(150px, 22vw);
    grid-template-rows: minmax(0, 1fr);
    gap: 18px;
    min-height: 0;
    margin: 0 auto;
    padding-bottom: var(--safe-bottom);
  }
  .current-card {
    grid-column: 1;
    grid-row: 1;
    min-height: 0;
  }
  .dealt-section {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    margin: 0;
    overflow: hidden;
  }
  .dealt-section h2 {
    flex: 0 0 auto;
    margin-top: 0;
  }
  .dealt-strip {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0 4px 8px 0;
  }
  .dealt-strip .card-frame {
    display: block;
    flex: 0 0 auto;
    width: min(100%, 140px);
    height: auto;
  }
  .dealt-strip img {
    display: block;
    width: 100%;
    height: auto;
    max-height: none;
  }
}

/* Fold inner portrait: reserve a fixed bottom strip for dealt cards even if iOS reduces the app viewport height. */
@media (min-width: 600px) and (max-width: 680px) and (orientation: portrait) and (min-aspect-ratio: 2/3) and (max-aspect-ratio: 4/5) {
  html,
  body {
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
  body {
    display: flex;
    flex-direction: column;
  }
  .topbar {
    position: relative;
    flex: 0 0 auto;
  }
  .main {
    width: 100%;
    max-width: none;
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 0 auto;
    padding: 12px calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left));
  }
  .current-card {
    flex: 1 1 0;
    min-height: 0;
  }
  .card-frame {
    width: min(100%, 78vw);
  }
  .card-frame img {
    max-height: 58vh;
  }
  .dealt-section {
    display: flex;
    flex: 0 0 128px;
    flex-direction: column;
    min-height: 0;
    margin: 10px 0 0;
    overflow: hidden;
  }
  .dealt-section h2 {
    flex: 0 0 auto;
    margin: 0 0 6px;
  }
  .dealt-strip {
    display: flex;
    flex: 1 1 0;
    min-height: 0;
    gap: 8px;
    align-items: flex-end;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 0 4px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .dealt-strip .card-frame {
    display: inline-block;
    flex: 0 0 auto;
    width: auto;
    height: auto;
  }
  .dealt-strip img {
    display: block;
    width: auto;
    height: 84px;
    max-height: 84px;
  }
}

:root.fold-outer,
:root.fold-inner-landscape,
:root.fold-inner-portrait,
:root.fold-outer body,
:root.fold-inner-landscape body,
:root.fold-inner-portrait body {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

:root.fold-outer body,
:root.fold-inner-landscape body,
:root.fold-inner-portrait body {
  display: flex;
  flex-direction: column;
}

:root.fold-outer .topbar,
:root.fold-inner-landscape .topbar,
:root.fold-inner-portrait .topbar {
  position: relative;
  flex: 0 0 auto;
}

:root.fold-outer .topbar {
  grid-template-columns: 1fr;
  align-items: start;
  gap: 0;
  padding-top: calc(8px + var(--safe-top));
  padding-right: calc(8px + var(--safe-right));
  backdrop-filter: none;
}
:root.fold-outer .controls {
  position: fixed;
  z-index: 20;
  right: calc(8px + var(--safe-right));
  bottom: calc(12px + var(--safe-bottom));
  width: 100px;
  padding: 8px;
  flex-direction: column !important;
  align-items: stretch;
  gap: 6px;
  border: 1px solid rgba(134, 239, 172, .45);
  border-radius: 16px;
  background: rgba(4, 45, 32, .94);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  backdrop-filter: blur(10px);
}
:root.fold-outer .controls #btn-start { order: 1; }
:root.fold-outer .controls #btn-restart { order: 2; }
:root.fold-outer .controls #btn-faster { order: 3; }
:root.fold-outer .controls #btn-slower { order: 4; }
:root.fold-outer .controls #btn-pause { order: 5; }
:root.fold-outer .controls #btn-speech { order: 6; }
:root.fold-outer .controls #btn-language { order: 7; }
:root.fold-outer .status {
  width: auto;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: 16px;
  padding: 4px 2px 8px;
}
:root.fold-outer .status span { white-space: nowrap; }
:root.fold-outer .btn {
  flex: 0 0 auto;
  width: 100%;
  min-height: 44px;
  padding: 6px 4px;
  font-size: 11px;
}
:root.fold-outer .main {
  width: auto;
  max-width: none;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 12px calc(116px + var(--safe-right)) 12px 8px;
  padding: 0 0 calc(8px + var(--safe-bottom));
}
:root.fold-outer .current-card { flex: 1 1 0; min-height: 0; }
:root.fold-outer .dealt-section {
  display: flex;
  flex: 0 0 104px;
  flex-direction: column;
  min-height: 0;
  margin: 8px 0 0;
  overflow: hidden;
}
:root.fold-outer .dealt-section h2 { flex: 0 0 auto; margin: 0 0 6px; }
:root.fold-outer .dealt-strip {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 0 4px;
  align-items: flex-end;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
:root.fold-outer .dealt-strip .card-frame,
:root.fold-inner-portrait .dealt-strip .card-frame {
  display: inline-block;
  flex: 0 0 auto;
  width: auto;
  height: auto;
}
:root.fold-outer .dealt-strip img { display: block; height: 60px; width: auto; }

:root.fold-inner-landscape .main {
  max-width: 1400px;
  width: 100%;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, 22vw);
  grid-template-rows: minmax(0, 1fr);
  gap: 18px;
  min-height: 0;
  margin: 0 auto;
  padding-bottom: var(--safe-bottom);
}
:root.fold-inner-landscape .current-card { grid-column: 1; grid-row: 1; min-height: 0; }
:root.fold-inner-landscape .dealt-section {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
}
:root.fold-inner-landscape .dealt-section h2 { flex: 0 0 auto; margin-top: 0; }
:root.fold-inner-landscape .dealt-strip {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 4px 8px 0;
}
:root.fold-inner-landscape .dealt-strip .card-frame {
  display: block;
  flex: 0 0 auto;
  width: min(100%, 140px);
  height: auto;
}
:root.fold-inner-landscape .dealt-strip img {
  display: block;
  width: 100%;
  height: auto;
  max-height: none;
}

:root.fold-inner-portrait .main {
  width: 100%;
  max-width: none;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0 auto;
  padding: 12px calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left));
}
:root.fold-inner-portrait .current-card { flex: 1 1 0; min-height: 0; }
:root.fold-inner-portrait .card-frame { width: min(100%, 78vw); }
:root.fold-inner-portrait .card-frame img { max-height: 58vh; }
:root.fold-inner-portrait .dealt-section {
  display: flex;
  flex: 0 0 128px;
  flex-direction: column;
  min-height: 0;
  margin: 10px 0 0;
  overflow: hidden;
}
:root.fold-inner-portrait .dealt-section h2 { flex: 0 0 auto; margin: 0 0 6px; }
:root.fold-inner-portrait .dealt-strip {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
  gap: 8px;
  align-items: flex-end;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 0 4px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
:root.fold-inner-portrait .dealt-strip img {
  display: block;
  width: auto;
  height: 84px;
  max-height: 84px;
}

/* Print styles */
@media print {
  .version-counter { display: none; }
}
@media print {
  .topbar,
  .dealt-section {
    display: none;
  }
}
