:root {
  --paper: #f1e9d6;          /* paper */
  --turquoise: #20b2aa;      /* approximation */
  --orange: #f3852e;         /* orange chalk */
  --brown: #8a5a3b;          /* leather/brown */
  --ink: #2a2a2a;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  font-family: "Lora", serif;
  color: var(--ink);
}

body {
  background-image: url('background.png'); /* crumpled paper texture */
  background-size: 260px 260px;
  background-repeat: repeat;
}

/* Orientation overlay for portrait mode */
.orientation-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(42, 42, 42, 0.95);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: white;
  text-align: center;
}

.orientation-overlay.show {
  display: flex;
}

.orientation-overlay h2 {
  font-size: 2rem;
  margin: 0 0 1rem 0;
  font-weight: 700;
}

.orientation-overlay p {
  font-size: 1rem;
  margin: 0 0 2rem 0;
  opacity: 0.8;
}

.device-icon {
  width: 80px;
  height: 80px;
  border: 3px solid var(--orange);
  border-radius: 12px;
  position: relative;
  animation: rotateDevice 2s ease-in-out infinite;
}

.device-icon::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: 8px;
  border: 2px solid var(--orange);
  border-radius: 6px;
}

@keyframes rotateDevice {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(90deg); }
}

/* Main layout - landscape only */
.app-container {
  display: none;
  min-height: 100vh;
  flex-direction: column;
}

.app-container.show {
  display: flex;
}

/* Header */
.header {
  padding: 1.5rem 2rem;
  border-bottom: 3px solid var(--brown);
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(2px);
}

.header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
  color: var(--brown);
}

.header::after {
  content: '';
  display: block;
  width: 100px;
  height: 3px;
  background: var(--orange);
  margin-top: 0.5rem;
}

/* Main content area */
.main-content {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 2rem;
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
}

/* Machines card */
.machines-card {
  background: rgba(255, 255, 255, 0.8);
  border: 3px solid var(--brown);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 2px 3px 0 var(--brown);
  position: relative;
}

.machines-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--orange);
  border-radius: 13px 13px 0 0;
}

.machines-card h2 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 1.5rem 0;
  color: var(--ink);
}

.machines-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.machine-button {
  aspect-ratio: 1;
  border: 2px solid var(--brown);
  border-radius: 14px;
  background: white;
  color: var(--ink);
  font-size: 1.5rem;
  font-weight: 700;
  font-family: "Lora", serif;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}

.machine-button:hover,
.machine-button:focus {
  background: rgba(32, 178, 170, 0.12);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  outline: 2px solid var(--turquoise);
  outline-offset: 2px;
}

.machine-button:active {
  transform: translateY(1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Sidebar */
.sidebar {
  background: rgba(255, 255, 255, 0.8);
  border: 3px solid var(--brown);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 2px 3px 0 var(--brown);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-button {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 12px;
  transition: all 0.15s ease;
  text-align: left;
  width: 100%;
}

.sidebar-button:hover,
.sidebar-button:focus {
  background: rgba(32, 178, 170, 0.1);
  outline: 2px solid var(--turquoise);
  outline-offset: 2px;
}

.icon-badge {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--orange);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.sidebar-button:hover .icon-badge,
.sidebar-button:focus .icon-badge {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(243, 133, 46, 0.3);
}

.icon-badge img {
  width: 40px;
  height: 40px;
}

.sidebar-button-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(42, 42, 42, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-backdrop.show {
  display: flex;
}

.modal-card {
  background: white;
  border: 3px solid var(--brown);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  max-width: 900px;
  width: 95%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-header {
  padding: 1.5rem 2rem 1rem;
  border-bottom: 2px solid var(--brown);
  position: relative;
}

.modal-title {
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
  color: var(--ink);
  padding-right: 3rem;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--brown);
  color: white;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.2rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.modal-close:hover,
.modal-close:focus {
  background: var(--orange);
  outline: 2px solid var(--turquoise);
  outline-offset: 2px;
}

.modal-body {
  padding: 2rem 3rem 3rem;
}

.modal-body p {
  line-height: 1.8;
  margin: 0 0 1.5rem 0;
  font-size: 1.1rem;
}

.modal-body p:last-child {
  margin-bottom: 0;
}

/* Screen reader only text */
.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;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .main-content {
    grid-template-columns: 1fr 250px;
    gap: 1rem;
    padding: 1rem;
  }

  .machines-card {
    padding: 1.5rem;
  }

  .machine-button {
    min-height: 60px;
    font-size: 1.2rem;
  }

  .header h1 {
    font-size: 1.5rem;
  }
}

@media (max-width: 600px) {
  .main-content {
    grid-template-columns: 1fr 200px;
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .machines-grid {
    gap: 0.75rem;
  }

  .machine-button {
    min-height: 50px;
    font-size: 1rem;
  }

  .sidebar {
    padding: 1rem;
  }

  .icon-badge {
    width: 48px;
    height: 48px;
  }

  .icon-badge img {
    width: 32px;
    height: 32px;
  }
}

/* Portrait orientation - show overlay */
@media (orientation: portrait) {
  .orientation-overlay {
    display: flex;
  }

  .app-container {
    display: none;
  }
}

:root{
  --paper:#f1e9d6; --turquoise:#20b2aa; --orange:#f3852e;
  --brown:#8a5a3b; --ink:#2a2a2a;
}
*{ box-sizing:border-box; }
html,body{ height:100%; margin:0; background:#e8e0cc; }
body{
  font-family:"Lora",serif; color:var(--ink);
  display:flex; flex-direction:column; gap:.5rem;
  background-image:url('background.png'); background-size:260px 260px; background-repeat:repeat;
}
header{
  display:flex; align-items:center; justify-content:space-between;
  padding:.6rem 1rem; border-bottom:3px solid var(--brown);
  background:rgba(255,255,255,.6); backdrop-filter:blur(2px);
}
.title{ font-weight:700; color:var(--brown); letter-spacing:.25px; }
.controls{ display:flex; gap:.6rem; }
.btn{
  display:flex; align-items:center; gap:.45rem;
  background:#fff; border:2px solid var(--brown); border-radius:10px;
  padding:.35rem .7rem; cursor:pointer; user-select:none;
  transition:.15s transform ease; box-shadow:1px 2px 0 var(--brown);
}
.btn:active{ transform:translateY(1px); box-shadow:0 1px 0 var(--brown); }
.btn img{ height:22px; width:auto; }
.btn.play{ border-color:var(--orange); box-shadow:1px 2px 0 var(--orange);}
.btn.reset{ border-color:var(--turquoise); box-shadow:1px 2px 0 var(--turquoise);}

.wrap{
  display:grid; grid-template-columns:220px 1fr 240px; gap:12px;
  padding:12px; max-width:1200px; margin:0 auto; width:100%;
}
.card{
  background:rgba(255,255,255,.75);
  border:3px solid var(--brown); border-radius:14px; padding:10px;
  box-shadow:2px 3px 0 var(--brown);
}
.board{ position:relative; overflow:hidden; }
#game{ display:block; width:100%; height:auto; background:transparent; }
.hud{ position:absolute; inset:0; pointer-events:none; }
.banner{
  position:absolute; left:50%; top:16px; transform:translateX(-50%);
  background:#fff; border:3px solid var(--orange); padding:.5rem .8rem;
  border-radius:12px; box-shadow:2px 3px 0 var(--orange); display:none;
}
.banner.show{ display:block; }
footer{ text-align:center; font-size:.85rem; color:#5b4a3f; opacity:.9; padding:8px 0 16px; }
.muted{ color:#666; font-size:.95rem; line-height:1.3; }

.toolbox-title { margin:.1rem 0 .5rem; }
.tool{
  border:2px dashed var(--brown); border-radius:12px; padding:10px;
  background:#fff; cursor:grab; user-select:none; margin-bottom:10px;
  display:flex; align-items:center; gap:.5rem; justify-content:space-between;
}
.tool:active{ cursor:grabbing; }
.chip{ font-size:.8rem; color:#fff; background:var(--orange);
  padding:.15rem .5rem; border-radius:999px; border:1px solid #d26e1f;}
canvas { border:1px solid #333; }
.badge{ color:#fff; background:var(--turquoise); padding:.05rem .45rem; border-radius:8px; }
